Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active March 22, 2024 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pointofpresence/b97c2b0033da79775ff6a967f69ff814 to your computer and use it in GitHub Desktop.
Save pointofpresence/b97c2b0033da79775ff6a967f69ff814 to your computer and use it in GitHub Desktop.
javascript:void function(){function truncateString(e,t){return e.length>t?e.slice(0,t):e}const title=document.title,href=location.href,host=new URL(href).host,cleanHost=host.replace(/[^a-zA-Z0-9]/g,"-");let finalHost=cleanHost.replace(/--/g,"-");finalHost.length||(finalHost="local");let sel=window.getSelection().toString();0===sel.length&&(sel=prompt("Description"));let text=`## ${title}\n\n${href}${sel&&sel.length>0?`\n\n${sel}`:""}`;const textarea=document.createElement("textarea");textarea.value=text,document.body.appendChild(textarea),textarea.select(),document.execCommand("copy");let command=`obsidian://advanced-uri?filepath=__INBOX/${finalHost}&mode=new`;if(document.queryCommandSupported("copy")){const e=document.execCommand("copy");document.body.removeChild(textarea),e?(console.log("Текст успешно скопирован в буфер обмена"),command=`obsidian://advanced-uri?filepath=__INBOX/${finalHost}&clipboard=true&mode=new`):(console.error("Перенос через URL"),command=truncateString(`${command}&data=${text=encodeURIComponent(text)}`,2046))}window.location.href=command;}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment