Skip to content

Instantly share code, notes, and snippets.

@billygoat
Last active February 26, 2024 07:03
Show Gist options
  • Save billygoat/5321349 to your computer and use it in GitHub Desktop.
Save billygoat/5321349 to your computer and use it in GitHub Desktop.
Drafts Bookmarklet
javascript:(function(){
var w=window,d=document,pageSelectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageTitle=d.title,pageUri=w.location.href,tmplt="";
tmplt="Title: "+pageTitle+"\nLink: "+pageUri+"\n\n";
if(pageSelectedTxt!="") {
pageSelectedTxt=">%20"+pageSelectedTxt;
pageSelectedTxt=pageSelectedTxt.replace(/(\r\n|\n+|\r)/gm,"\n");
pageSelectedTxt=pageSelectedTxt.replace(/\n/g,"\n>%20\n>%20");
}
w.location.href="drafts://x-callback-url/create/?text="+encodeURIComponent(tmplt+pageSelectedTxt);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment