-
-
Save brysmi/1180245 to your computer and use it in GitHub Desktop.
A smarter bookmarklet for Pinboard.in; wraps selected text in <blockquote> tags, keeps variables out of the global scope, supports filling tags from rel="tag" markup in the page, and titles from hAtom entry titles. (brysmi) I've added meta "description"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (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; | |
// uncommment to open your pinboard page in chrome | |
// var re = new RegExp("^chrome://(.*)"); | |
// if (re.test(url)) { | |
// window.location = "http://pinboard.in/u:username"; | |
// return; | |
// } | |
// 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(''); | |
} | |
else { | |
var s = [], | |
metas = document.getElementsByTagName('head')[0].getElementsByTagName('meta'); | |
for (var i = 0, L = metas.length; i < L; i++) { | |
if (metas[i].name == 'description') { | |
s[s.length] = metas[i].content; | |
} | |
} | |
text = s.join(','); | |
if (text.length === 0) { | |
// silent = true; | |
} | |
else { | |
// I should take 2 minutes to clean this | |
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(); | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){var%20b=location.href,e=document.title;if(document.querySelector&&1===document.getElementsByClassName("hentry").length)e=document.querySelector(".hentry%20.entry-title,%20.hentry%20h1,%20.hentry%20h2,%20.hentry%20h3").innerText;if(""!==(text=String(document.getSelection())))text=["<blockquote>",text,"</blockquote>\n\n"].join("");else{for(var%20c=[],d=document.getElementsByTagName("head")[0].getElementsByTagName("meta"),a=0,f=d.length;a<f;a++)if(d[a].name=="description")c[c.length]=d[a].content;text=c.join(","); | |
text.length!==0&&(text=["<blockquote>",text,"</blockquote>\n\n"].join(""))}if(document.querySelectorAll)var%20g=[].slice.call(document.querySelectorAll("a[rel~=tag]"),0).map(function(a){return%20a.href.split("/").pop()}).join("%20");b=["http://pinboard.in/add?url=",encodeURIComponent(b),"&description=",encodeURIComponent(text),"&tags",encodeURIComponent(g),"&title=",encodeURIComponent(e)];open(b.join(""),"Pinboard","toolbar=no,width=610,height=350")})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment