-
-
Save BenWard/801657 to your computer and use it in GitHub Desktop.
| (function() { | |
| // Change `silent` to true to invoke the promptless, self-closing | |
| // version of the bookmarklet. | |
| var silent = false; | |
| var url = location.href; | |
| var title = document.title; | |
| // Look for a single hAtom entry on the page, and iff one is found, extract | |
| // the entry-title in place of the document title: | |
| if(document.querySelector) { | |
| if(1 === document.getElementsByClassName('hentry').length) { | |
| title = document.querySelector( | |
| '.hentry .entry-title, .hentry h1, .hentry h2, .hentry h3' | |
| ).innerText; | |
| } | |
| } | |
| // Grab the text selection (if any) and <blockquote> it in the description. | |
| if('' !== (text = String(document.getSelection()))) { | |
| text = ['<blockquote>', text, '</blockquote>', "\n\n"].join(''); | |
| } | |
| // Grab all rel-tag microformats from the page and prefix the tags param | |
| if(document.querySelectorAll) { | |
| var tags = [].slice.call( | |
| document.querySelectorAll('a[rel~=tag]'),0).map( | |
| function(a) { | |
| return a.href.split('/').pop(); | |
| } | |
| ).join(' '); | |
| } | |
| // Assembles default form pre-fill arguments. | |
| // Note: 'tags' is not currently supported but should be. | |
| var args = [ | |
| 'http://pinboard.in/add?url=', encodeURIComponent(url), | |
| '&description=', encodeURIComponent(text), | |
| '&tags', encodeURIComponent(tags), | |
| '&title=', encodeURIComponent(title) | |
| ]; | |
| // If silent mode, add the auto-close parameter and read-later flag: | |
| if(silent) { | |
| args = args.concat([ | |
| '&later=', 'yes', | |
| '&jump=', 'close' | |
| ]); | |
| } | |
| var pin = open(args.join(''), 'Pinboard', 'toolbar=no,width=610,height=350'); | |
| // Send the window to the background if silent mode. | |
| if(silent) { | |
| pin.blur(); | |
| } | |
| })(); |
| javascript:(function()%20{var%20silent%20=%20true;var%20url%20=%20location.href;var%20title%20=%20document.title;if(document.querySelector)%20{if(1%20===%20document.getElementsByClassName(%27hentry%27).length)%20{title%20=%20document.querySelector(%27.hentry%20.entry-title,%20.hentry%20h1,%20.hentry%20h2,%20.hentry%20h3%27).innerText;}}if(%27%27%20!==%20(text%20=%20String(document.getSelection())))%20{text%20=%20[%27<blockquote>%27,%20text,%20%27</blockquote>%27,%20%22\n\n%22].join(%27%27);}if(document.querySelectorAll)%20{var%20tags%20=%20[].slice.call(document.querySelectorAll(%27a[rel~=tag]%27),0).map(function(a)%20{return%20a.href.split(%27/%27).pop();}).join(%27%20%27);}var%20args%20=%20[%27http://pinboard.in/add?url=%27,%20encodeURIComponent(url),%27&description=%27,%20encodeURIComponent(text),%27&tags%27,%20encodeURIComponent(tags),%27&title=%27,%20encodeURIComponent(title)];if(silent)%20{args%20=%20args.concat([%27&later=%27,%20%27yes%27,%27&jump=%27,%20%27close%27]);}var%20pin%20=%20open(args.join(%27%27),%20%27Pinboard%27,%20%27toolbar=no,width=610,height=350%27);if(silent)%20{pin.blur();}})(); |
| javascript:(function()%20{var%20silent%20=%20false;var%20url%20=%20location.href;var%20title%20=%20document.title;if(document.querySelector)%20{if(1%20===%20document.getElementsByClassName(%27hentry%27).length)%20{title%20=%20document.querySelector(%27.hentry%20.entry-title,%20.hentry%20h1,%20.hentry%20h2,%20.hentry%20h3%27).innerText;}}if(%27%27%20!==%20(text%20=%20String(document.getSelection())))%20{text%20=%20[%27<blockquote>%27,%20text,%20%27</blockquote>%27,%20%22\n\n%22].join(%27%27);}if(document.querySelectorAll)%20{var%20tags%20=%20[].slice.call(document.querySelectorAll(%27a[rel~=tag]%27),0).map(function(a)%20{return%20a.href.split(%27/%27).pop();}).join(%27%20%27);}var%20args%20=%20[%27http://pinboard.in/add?url=%27,%20encodeURIComponent(url),%27&description=%27,%20encodeURIComponent(text),%27&tags%27,%20encodeURIComponent(tags),%27&title=%27,%20encodeURIComponent(title)];if(silent)%20{args%20=%20args.concat([%27&later=%27,%20%27yes%27,%27&jump=%27,%20%27close%27]);}var%20pin%20=%20open(args.join(%27%27),%20%27Pinboard%27,%20%27toolbar=no,width=610,height=350%27);if(silent)%20{pin.blur();}})(); |
Awesome, thanks!
Thanks this is great (and much better than my home brewed solution). Although I really wish pinboard.in would allow for the tags field to be pre-filled.
Dear JC., To achieve that effect just search for &tags and change it to &tags=tag. Sincerely, JC
Fantastic! Thank you.
Hey - I just found this in a search because I wanted to auto-fill the description when bookmarking...and didn't realise that if you select text before using the standard bookmarklet, the description is populated with the selected text. But I worked that out once I used this bookmarklet and realised what was going on. So anyway - thanks for that!
I'm trying to work out why you're wrapping in blockquotes - why do you do that? Is it just a personal preference thing or am I missing something obvious?
thank you for this!