OrinZ (owner)

Fork Of

gist: 93982 by simonw singpolyma's bit.ly version...

Revisions

gist: 134325 Download_button fork
public
Description:
A bookmarklet to report the rev=canonical attribute if one exists, or alert if one does not.
Public Clone URL: git://gist.github.com/134325.git
Embed All Files: show embed
shorten-bookmarklet.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* bookmarklet for extracting rev=canonical if it exists, or simply notifying if one does not */
(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 {
        alert('No canonical url found.');
}
})();