Skip to content

Instantly share code, notes, and snippets.

@edvakf
Created February 24, 2009 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edvakf/69794 to your computer and use it in GitHub Desktop.
Save edvakf/69794 to your computer and use it in GitHub Desktop.
(function(){
var untiny = function(){
var doc = document;
var api='http://atsushaa.appspot.com/untiny/get?url=URLS&callback=untinyUrl';
function xGet(xpath){
xpath+=xpath.replace(/^\/\//,'|//x:');
var res=doc.evaluate(xpath,doc,function(){return 'http://www.w3.org/1999/xhtml'},6,null);
var ret=[];
for(var i=0,l=res.snapshotLength;i<l;i++){
ret[i]=res.snapshotItem(i);
}
return ret;
}
var links=xGet('//a[starts-with(@href,\'http://tinyurl.com/\') or starts-with(@href,\'http://bit.ly/\') or starts-with(@href,\'http://is.gd/\')]').slice(0,10);
if(!links.length)return;
var script=doc.createElement('script');
script.src=api.replace('URLS',links.map(function(a){return encodeURIComponent(a.href)}).join('+'));
window.untinyUrl=function(untiny){
for(var url in untiny){
redirect=untiny[url];
if(/^http/.test(redirect)){
links.forEach(function(a){
if(a.href==url){
if(a.textContent==a.href){a.href=redirect;a.textContent=decodeURI(redirect)}
else{a.href=redirect;a.appendChild(doc.createTextNode(' ('+decodeURI(redirect)+')'))}
}
})
}
}
doc.documentElement.removeChild(script);
delete window.untinyUrl;
};
doc.documentElement.appendChild(script);
}
setInterval(untiny,5*1000);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment