Created
July 8, 2009 06:20
-
-
Save ucnv/142621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Permanize Monkey | |
// @namespace http://userscripts.org/users/40991 | |
// @description GM port of the Jetpack app http://app.permanize.org/ | |
// @include * | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js | |
// ==/UserScript== | |
// It's based on http://permanize.appspot.com/jetpack/permanize.js | |
var shorts = "bit.ly, cli.gs, digg.com, is.gd, tr.im, kl.am, tinyurl.com, 307.to, adjix.com, b23.ru, bacn.me, bloat.me, budurl.com, clipurl.us, cort.as, dwarfurl.com, ff.im, fff.to, href.in, idek.net, korta.nu, lin.cr, ln-s.net, loopt.us, lost.in, memurl.com, merky.de, migre.me, moourl.com, nanourl.se, ow.ly, peaurl.com, ping.fm, piurl.com, plurl.me, pnt.me, poprl.com, post.ly, rde.me, reallytinyurl.com, redir.ec, rubyurl.com, short.ie, short.to, smallr.com, sn.im, sn.vc, snipr.com, snipurl.com, snurl.com, tiny.cc, tinysong.com, togoto.us, tra.kz, trg.li, twurl.cc, twurl.nl, u.mavrev.com, u.nu, ur1.ca, url.az, url.ie, urlx.ie, w34.us, xrl.us, yep.it, zi.ma, zurl.ws, chilp.it, notlong.com, qlnk.net, trim.li". | |
split(/,\s*/) | |
var shortsLength = shorts.length; | |
var found = {}; | |
var blacklist = {}; | |
function replaceHref(a, shortUrl, longUrl) { | |
if(a.attr("href") === shortUrl && longUrl.indexOf("http://") === 0) { | |
a.attr("href", longUrl) | |
found[shortUrl] = longUrl | |
} | |
} | |
function handleAnchor(e) { | |
var self = this; | |
var href = self.href; | |
if(found[href]) { | |
return replaceHref($(self), href, found[href]) | |
} | |
if(href != "null" && href != "" && !blacklist[href] && href.indexOf("http://") === 0) { | |
for(var i = 0; i < shortsLength; ++i) { | |
if(href.indexOf(shorts[i]) === 7) { // "http://".length | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: "http://permanize.appspot.com/resolve/"+encodeURIComponent(href), | |
onload: function(res) { | |
replaceHref($(self), href, res.responseText) | |
}, | |
onerror: function (error) { | |
console.log(error) | |
} | |
}); | |
return; | |
} | |
} | |
// still here -> no match | |
blacklist[href] = true | |
} | |
} | |
(function (doc) { | |
var bind = function () { | |
$(doc).find("a").each(handleAnchor) | |
}; | |
bind(); | |
var timeout; | |
$(doc).bind("DOMNodeInserted", function () { | |
if(timeout) clearTimeout(timeout) | |
timeout = setTimeout(bind, 300) | |
}) | |
})(document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment