Skip to content

Instantly share code, notes, and snippets.

@os0x
Created January 15, 2011 09:20
Show Gist options
  • Save os0x/780806 to your computer and use it in GitHub Desktop.
Save os0x/780806 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name mouseover eijirox
// @description mouseover dictionary, require EijiroX and NinjaKit extensions.
// @namespace http://ss-o.net/
// @include http*
// ==/UserScript==
(function () {
var d = document.createElement('dl');
d.id = 'eijirox-box';
d.style.cssText = 'min-width:200px;min-height:100px;position:absolute!important;background:rgba(255,255,255,0.8)!important;color:#000!important;font-size:11px!important;border-radius:10px!important;padding:10px!important;margin:0px!important;text-align:left!important;line-height:1.2!important;z-index:10000000!important;border:2px solid #456!important;';
var T = document.TEXT_NODE;
var E = document.ELEMENT_NODE;
document.onmouseover = function (e) {
var n = e.target;
var data = n.dataset;
if (n.nodeType === E && !data.eijirox) {
if (n.disabled === false) {
return;
}
data.eijirox = true;
var nodes = Array.prototype.slice.call(n.childNodes);
nodes.reverse().forEach(function (t) {
if (t.nodeType === T) {
var point = 0,
p = t.parentNode,
st;
while ((point = t.nodeValue.search(/[-\w]/)) >= 0) {
if (point > 0) t = t.splitText(point);
var end = t.nodeValue.search(/[^-\w]/);
if (end >= 0) {
st = t.splitText(end);
} else {
st = t.nextSibling;
}
var f = document.createElement('font');
f.className = 'eijirox';
f.dataset.eijirox = true;
f.onmouseout = function () {
d.parentNode && document.body.removeChild(d);
}
f.appendChild(t);
p.insertBefore(f, st);
if (end === -1) {
break;
}
t = st;
}
}
});
}
if (n.className === 'eijirox' && /[a-zA-Z]/.test(n.textContent)) {
chrome.extension.sendRequest('incofakicgjnjoggkkepbldklfocgafh', {
action: 'search',
query: n.textContent,
page: 1,
full: false,
limit: 10,
html: true
}, function (response) {
if (response.results) {
d.innerHTML = response.results;
d.style.left = (e.pageX + 10) + 'px';
d.style.top = (e.pageY + 10) + 'px';
document.body.appendChild(d);
}
});
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment