Skip to content

Instantly share code, notes, and snippets.

@salathe
Forked from simonw/shorten-bookmarklet.js
Created May 12, 2010 19:30
Show Gist options
  • Save salathe/399031 to your computer and use it in GitHub Desktop.
Save salathe/399031 to your computer and use it in GitHub Desktop.
/* 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('Canonical URL:', found);
} else {
prompt('No declared canonical URL, here is the original:', url);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment