javascript:Promise.all([import('https://unpkg.com/turndown@6.0.0?module'),import('https://unpkg.com/@tehshrike/readability@0.2.0'),]).then(async([{default:Turndown},{default:Readability}])=>{/* Optional vault name */constvault="";/* Optional folder name such as "Clippings/" */constfolder="Clippings/";/* Optional tags */lettags="clippings";/* Parse the site's meta keywords content into tags, if present */if(document.querySelector('meta[name="keywords" i]')){varkeywords=document.querySelector('meta[name="keywords" i]').getAttribute('content').split(',');keywords.forEach(function(keyword){lettag=' '+keyword.split(' ').join('');tags+=tag;});}functiongetSelectionHtml(){varhtml="";if(typeofwindow.getSelection!="undefined"){varsel=window.getSelection();if(sel.rangeCount){varcontainer=document.createElement("div");for(vari=0,len=sel.rangeCount;i<len;++i){container.appendChild(sel.getRangeAt(i).cloneContents());}html=container.innerHTML;}}elseif(typeofdocument.selection!="undefined"){if(document.selection.type=="Text"){html=document.selection.createRange().htmlText;}}returnhtml;}constselection=getSelectionHtml();const{title,byline,content}=newReadability(document.cloneNode(true)).parse();functiongetFileName(fileName){varuserAgent=window.navigator.userAgent,platform=window.navigator.platform,windowsPlatforms=['Win32','Win64','Windows','WinCE'];if(windowsPlatforms.indexOf(platform)!==-1){fileName=fileName.replace(':','').replace(/[/\\?%*|"<>]/g,'-');}else{fileName=fileName.replace(':','').replace(/\//g,'-').replace(/\\/g,'-');}returnfileName;}constfileName=getFileName(title);if(selection){varmarkdownify=selection;}else{varmarkdownify=content;}if(vault){varvaultName='&vault='+encodeURIComponent(`${vault}`);}else{varvaultName='';}constmarkdownBody=newTurndown({headingStyle:'atx',hr:'---',bulletListMarker:'-',codeBlockStyle:'fenced',emDelimiter:'*',}).turndown(markdownify);vardate=newDate();functionconvertDate(date){varyyyy=date.getFullYear().toString();varmm=(date.getMonth()+1).toString();vardd=date.getDate().toString();varmmChars=mm.split('');varddChars=dd.split('');returnyyyy+'-'+(mmChars[1]?mm:"0"+mmChars[0])+'-'+(ddChars[1]?dd:"0"+ddChars[0]);}consttoday=convertDate(date);// Utility function to get meta content by name or property
functiongetMetaContent(attr,value){varelement=document.querySelector(`meta[${attr}='${value}']`);returnelement?element.getAttribute("content").trim():"";}// Fetch byline, meta author, property author, or site name
varauthor=byline||getMetaContent("name","author")||getMetaContent("property","author")||getMetaContent("property","og:site_name");// Check if there's an author and add brackets
varauthorBrackets=author?`"[[${author}]]"`:"";/* Try to get published date */vartimeElement=document.querySelector("time");varpublishedDate=timeElement?timeElement.getAttribute("datetime"):"";if(publishedDate&&publishedDate.trim()!==""){vardate=newDate(publishedDate);varyear=date.getFullYear();varmonth=date.getMonth()+1;// Months are 0-based in JavaScript
varday=date.getDate();// Pad month and day with leading zeros if necessary
month=month<10?'0'+month:month;day=day<10?'0'+day:day;varpublished=year+'-'+month+'-'+day;}else{varpublished=''}/* YAML front matter as tags render cleaner with special chars */constfileContent='---\n'+'category: "[[Clippings]]"\n'+'author: '+authorBrackets+'\n'+'title: "'+title+'"\n'+'source: '+document.URL+'\n'+'clipped: '+today+'\n'+'published: '+published+'\n'+'topics: \n'+'tags: ['+tags+']\n'+'---\n\n'+markdownBody;document.location.href="obsidian://new?"+"file="+encodeURIComponent(folder+fileName)+"&content="+encodeURIComponent(fileContent)+vaultName;})
Мой вариант
javascript:Promise.all([import('https://unpkg.com/turndown@6.0.0?module'),import('https://unpkg.com/@tehshrike/readability@0.2.0'),]).then(async([{default:Turndown},{default:Readability}])=>{/* zlonov: переменная для списка ключевых слов*/letzlonov_metawords="";/* zlonov: формирование списка мета-ключевых слов сайта, если таковые имеются */if(document.querySelector('meta[name="keywords" i]')){varkeywords=document.querySelector('meta[name="keywords" i]').getAttribute('content').split(',');keywords.forEach(function(keyword){letzlonov_metaword=' '+keyword.split(' ').join(' ');zlonov_metawords+=zlonov_metaword;});}functiongetSelectionHtml(){varhtml="";if(typeofwindow.getSelection!="undefined"){varsel=window.getSelection();if(sel.rangeCount){varcontainer=document.createElement("div");for(vari=0,len=sel.rangeCount;i<len;++i){container.appendChild(sel.getRangeAt(i).cloneContents());}html=container.innerHTML;}}elseif(typeofdocument.selection!="undefined"){if(document.selection.type=="Text"){html=document.selection.createRange().htmlText;}}returnhtml;}constselection=getSelectionHtml();const{title,byline,content}=newReadability(document.cloneNode(true)).parse();functiongetFileName(fileName){varuserAgent=window.navigator.userAgent,platform=window.navigator.platform,windowsPlatforms=['Win32','Win64','Windows','WinCE'];if(windowsPlatforms.indexOf(platform)!==-1){fileName=fileName.replace(':','').replace(/[/\\?%*|"<>]/g,'-');}else{fileName=fileName.replace(':','').replace(/\//g,'-').replace(/\\/g,'-');}returnfileName;}constfileName=getFileName(title);if(selection){varmarkdownify=selection;}else{varmarkdownify=content;}constmarkdownBody=newTurndown({headingStyle:'atx',hr:'---',bulletListMarker:'-',codeBlockStyle:'fenced',emDelimiter:'*',}).turndown(markdownify);vardate=newDate();functionconvertDate(date){varyyyy=date.getFullYear().toString();varmm=(date.getMonth()+1).toString();vardd=date.getDate().toString();varmmChars=mm.split('');varddChars=dd.split('');returnyyyy+'-'+(mmChars[1]?mm:"0"+mmChars[0])+'-'+(ddChars[1]?dd:"0"+ddChars[0]);}consttoday=convertDate(date);/* Try to get published date */vartimeElement=document.querySelector("time");varpublishedDate=timeElement?timeElement.getAttribute("datetime"):"";if(publishedDate&&publishedDate.trim()!==""){vardate=newDate(publishedDate);varyear=date.getFullYear();varmonth=date.getMonth()+1;// Months are 0-based in JavaScript
varday=date.getDate();// Pad month and day with leading zeros if necessary
month=month<10?'0'+month:month;day=day<10?'0'+day:day;varpublished=year+'-'+month+'-'+day;}else{varpublished=''}/* zonov: модифицированный YAML front matter */constfileContent='---\n'+'Хаб Злонова: \n'+'created: '+today+'\n'+'source: '+document.URL+'\n'+'tags: \n'+'date: '+published+'\n'+'---\n\n'+markdownBody+'\n\n'/* zonov: подвал сохранённой заметки */+'---\n'+'- _Источник: ['+document.domain+']('+document.URL+')_'+'\n'+'- _Мета слова: '+zlonov_metawords+'_';document.location.href="obsidian://new?"+"file="+encodeURIComponent(fileName)+"&content="+encodeURIComponent(fileContent);})