(function() { var l = (document.querySelector('[rev~="canonical"]') || document.querySelector('[rel~="alternate"][rel~="short"]') || document.querySelector('[rel~="shortlink"]') || document.querySelector('[rel~="alternate"][rel~="shorter"]')); if (l) { prompt("Short URL:", l.href); } else { window.shortUrlBookmarkletCallback = function(bitly) { if (bitly.status_code === 200) { prompt("Bit.ly URL:", bitly.data.url); } else { alert("Bit.ly error: " + bitly.status_txt); } }; var s = document.createElement('script'); s.type = 'text/javascript'; s.src = ('http://api.bit.ly/v3/shorten' + '?longURL=' + encodeURIComponent(window.location.href) + '&domain=j.mp' + '&format=json' + '&callback=shortUrlBookmarkletCallback' + '&login=BITLY_USERNAME' + '&apiKey=BITLY_API_KEY'); document.querySelector('head').appendChild(s); } })();