Created
January 17, 2009 04:53
-
-
Save youz/48265 to your computer and use it in GitHub Desktop.
Outputz.barchart.user.js
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 Outputz bar chart | |
// @namespace http://d.hatena.ne.jp/youz/ | |
// @include http://outputz.com/* | |
// ==/UserScript== | |
(function(){ | |
var make_uri = function (param) { | |
var q = ''; | |
for (k in param) { q += '&' + k + '=' + param[k]; } | |
return 'http://chart.apis.google.com/chart?' + q; | |
}; | |
var parse_uri = function (uri) { | |
var params = {}; | |
uri.split(/[?&]/g).slice(1).forEach( | |
function(s){ | |
var p = s.split(/=/); | |
params[p[0]] = p[1]; | |
}); | |
return params; | |
}; | |
var imgs=document.images; | |
for (var i=0; i<imgs.length; ++i) { | |
if (imgs[i].src.match(/cht=p3/)) { | |
var p = parse_uri(imgs[i].src); | |
var d = p['chd'].substr(2).split(',').map(parseFloat); | |
var dmax = Math.ceil(Math.max.apply(null, d)/10)*10; | |
var params = { | |
'chs': '500x420', | |
'chbh': (320/d.length).toFixed(), | |
'cht': 'bhs', | |
'chco': p['chco'] || '4d89f9', | |
'chd': 't:' + d.reverse().join(','), | |
'chds': '0,' + dmax, | |
'chg': '10,0', | |
'chxt': 'x,y', | |
'chxl': ['0:', [0,1,2,3,4,5].map(function(i){ return dmax*i/5; }).join('|'), | |
'1:', p['chl'] | |
].join('|') | |
}; | |
imgs[i].src = make_uri(params); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment