Skip to content

Instantly share code, notes, and snippets.

@satyr
Created September 18, 2010 13:13
Show Gist options
  • Save satyr/585657 to your computer and use it in GitHub Desktop.
Save satyr/585657 to your computer and use it in GitHub Desktop.
Hatena Graph Previewer
// ==UserScript==
// @name Hatena Graph Previewer
// @namespace http://twitter.com/m_satyr
// @include http://graph.hatena.ne.jp/*/edit*
// @license X
// ==/UserScript==
var gedit = document.getElementById('graphedit');
var table = gedit.querySelector('table');
var graph = gedit.appendChild(new Image);
var titles = document.getElementById('titlecel').children;
var iscell = /^t[hd]$/i;
var curidx = 1;
graph.id = 'graph';
preview({target: table.querySelector('th:nth-child(2)')});
table.addEventListener('mouseover', preview, false);
table.addEventListener('change', preview, false);
function preview(ev){
var lm = ev.target;
for(;; lm = lm.parentNode)
if(lm == table) return;
else if(iscell.test(lm.nodeName)) break;
var sibs = lm.parentNode.children, len = sibs.length, idx = len;
while(sibs[--idx] != lm);
if(idx < 1 || len - 3 < idx ||
idx == curidx && ev.type == 'mouseover') return;
curidx = idx;
setTimeout(function(){
var name = graph.title = graph.alt = titles[idx].textContent.trim();
graph.src = (/^\/[^/]+/(location.pathname) +'/graph?graphname='+
encodeURIComponent(name) +'&mode=detail&'+ Date.now());
}, 9);
}
@satyr
Copy link
Author

satyr commented Sep 18, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment