Skip to content

Instantly share code, notes, and snippets.

@simonw
Created April 11, 2009 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save simonw/93591 to your computer and use it in GitHub Desktop.
Save simonw/93591 to your computer and use it in GitHub Desktop.
Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page
/* 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' || (/alternate short/).exec(l.getAttribute('rel'))) {
found=l.getAttribute('href');
break;
}
}
if (!found) {
for (var i = 0; l = document.links[i]; i++) {
if (l.getAttribute('rev') == 'canonical') {
found = l.getAttribute('href');
break;
}
}
}
if (found) {
prompt('URL:', found);
} else {
window.onTinyUrlGot = function(r) {
if (r.ok) {
prompt('URL:', r.tinyurl);
} else {
alert('Could not shorten with tinyurl');
}
};
var s = document.createElement('script');
s.type='text/javascript';
s.src='http://json-tinyurl.appspot.com/?callback=onTinyUrlGot&url=' + 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