Created
May 30, 2010 02:24
-
-
Save jpwatts/418716 to your computer and use it in GitHub Desktop.
A bookmarklet for finding a short URL for a page
This file contains 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 l=(document.querySelector('[rev~="canonical"]')||document.querySelector('[rel~="alternate"][rel~="short"]')||document.querySelector('[rel~="shortlink"]')||document.querySelector('[rel~="shorturl"]')||document.querySelector('[rel~="alternate"][rel~="shorter"]'));if(l){prompt("Short URL:",l.getAttribute('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);}})(); | |
(function() { | |
var l = (document.querySelector('[rev~="canonical"]') | |
|| document.querySelector('[rel~="alternate"][rel~="short"]') | |
|| document.querySelector('[rel~="shortlink"]') | |
|| document.querySelector('[rel~="shorturl"]') | |
|| document.querySelector('[rel~="alternate"][rel~="shorter"]')); | |
if (l) { | |
prompt("Short URL:", l.getAttribute('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); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment