Created
September 18, 2010 13:13
-
-
Save satyr/585657 to your computer and use it in GitHub Desktop.
Hatena Graph Previewer
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 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://help-me-hackers.com/tasks/133