[image]
simonw (owner)

Forks

gist: 93707 by colin created April 11, 2009 gist: 93761 by singpolyma created April 11, 2009 gist: 101510 by adelcambre created April 24, 2009 gist: 399031 by salathe created May 12, 2010 gist: 638071 by lancewi... Add support for shortlink created October 20, 2010

Revisions

2636b8 simonw April 12, 2009 eda7bb simonw April 11, 2009 a10138 simonw April 11, 2009
gist: 93591 Download_button fork
public
public
Description:
Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page
Public Clone URL: git://gist.github.com/93591.git
Give this clone URL to anyone.
git clone git://gist.github.com/93591.git gist-93591
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
33
34
35

/* 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);
    }
})();
Please log in to comment.


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser