singpolyma (owner)

Fork Of

gist: 93591 by simonw Expanded form of a bookmark...

Forks

  • gist: 93942 by atl Added rel="short_url" case created Sun Apr 12 03:01:22 -0700 2009
  • gist: 93982 by simonw singpolyma's bit.ly version... created Sun Apr 12 05:32:27 -0700 2009

Revisions

gist: 93761 Download_button fork
public
Public Clone URL: git://gist.github.com/93761.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
26
27
28
29
30
31
32
/* 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) {
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);
}
})();