-
-
Save tobynet/585660 to your computer and use it in GitHub Desktop.
Hatena Graph Previewer http://help-me-hackers.com/tasks/133
This file contains hidden or 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* | |
// ==/UserScript== | |
// | |
// Released under the MIT license | |
// modified by http://twitter.com/toby_net | |
// see also | |
// http://help-me-hackers.com/tasks/133 | |
var gedit = document.getElementById('graphedit'); | |
var table = gedit.querySelector('table'); | |
var graph = gedit.appendChild(new Image); | |
var titles = document.getElementById('titlecel'); | |
var iscell = /^t[hd]$/i; | |
graph.id = 'graph'; | |
graph.style.cssText = "display: none; position: absolute; padding:16px;" | |
+ "opacity: 0.90; background-color: #F4F4FF; -moz-border-radius: 6px;"; | |
table.addEventListener('mouseover', preview, false); | |
table.addEventListener('mouseout', hidePreview, false); | |
table.addEventListener('change', preview, false); | |
var ev = {target: table.querySelector('th:nth-child(2)')}; | |
//preview(ev); | |
hidePreview(ev); | |
function preview(ev){ | |
var lm = ev.target; | |
for(;; lm = lm.parentNode){ | |
if(lm == table) return; | |
if(iscell.test(lm.nodeName)) break; | |
} | |
var sibs = lm.parentNode.children, idx = index(sibs, lm); | |
if(idx < 1 || sibs.length - 2 < idx) return; | |
setTimeout(function(name){ | |
graph.style.display = ""; | |
graph.style.left = ev.clientX + document.body.scrollLeft + 16 + 'px'; | |
graph.style.top = ev.clientY + document.body.scrollTop + 0 + 'px';; | |
graph.title = graph.alt = name; | |
graph.src = (/^\/[^/]+/(location.pathname) +'/graph?graphname='+ | |
encodeURIComponent(name) + '&mode=detail' +'&'+ +new Date); | |
}, 9, titles.children[idx].textContent.trim()); | |
} | |
function hidePreview(ev) { | |
graph.style.display = "none"; | |
} | |
function index(lmns, lmn){ | |
for(let i = -1, it; it = lmns[++i];) if(it == lmn) return i; | |
return -1; | |
} |
問題ないよね
無論です。最初のバージョンに書き忘れててすみません。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元のタスクがMITライセンスでってことなのでMITライセンスって書いといた(問題ないよね
詳細 http://help-me-hackers.com/tasks/133