Skip to content

Instantly share code, notes, and snippets.

@satyr
Created December 2, 2008 14:33
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 satyr/31130 to your computer and use it in GitHub Desktop.
Save satyr/31130 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AutoLongURLize
// @description Expands shorten/image URLs. (powered by longurl.org)
// @namespace http://d.hatena.ne.jp/murky-satyr
// @include http://twitter.com/*
// ==/UserScript==
const ReLnk = /^\s*https?:/, ReImg = /\.(jpe?g|png|gif)\s*$/;
function alu(d) Array.forEach(d, function(e){
Array.forEach(e.getElementsByTagName('a'), function(a){
with(a) ReLnk.test(innerHTML) && GM_xmlhttpRequest({
url: 'http://api.longurl.org/v1/expand?format=json&url='+ href,
method: 'get',
onload: function(x){
if(x.status !== 200) return;
var {long_url, title} = eval('0,'+ x.responseText);
if(!long_url) return;
if(ReImg.test(long_url))
innerHTML = '<img border=0 src="'+ long_url +'"/>';
else {
var h = decodeURIComponent(long_url);
innerHTML = title ? title +' ('+ h +')' : h;
}
}});
});
});
alu([document]);
setTimeout(function() self.AutoPagerize && AutoPagerize.addFilter(alu));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment