Skip to content

Instantly share code, notes, and snippets.

@atl
Forked from singpolyma/shorten-bookmarklet.js
Created April 12, 2009 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atl/93942 to your computer and use it in GitHub Desktop.
Save atl/93942 to your computer and use it in GitHub Desktop.
Added rel="short_url" case
/* Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page */
(function(){
var url=document.location;
var links=document.getElementsByTagName('link');
var found=0;
for(var i = 0, l; l = links[i]; i++) {
if (l.getAttribute('rev') == 'canonical' || (!(/icon/).exec(l.getAttribute('rel')) && (/short/).exec(l.getAttribute('rel')))) {
found=l.getAttribute('href');
break;
}
}
if (found) {
prompt('URL:', found);
} else {
window.onTinyUrlGot = function(r) {
if (r.errorCode == 0) {
var t;
for(var i in r.results) {
t = r.results[i].shortUrl;
}
prompt('URL:', t);
} else {
alert('Could not shorten with bit.ly');
}
};
var s = document.createElement('script');
s.type='text/javascript';
s.src='http://api.bit.ly/shorten?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&version=2.0.1&callback=onTinyUrlGot&longUrl=' + encodeURIComponent(document.location);
document.getElementsByTagName('head')[0].appendChild(s);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment