Skip to content

Instantly share code, notes, and snippets.

@meso
Created June 24, 2009 05:18
Show Gist options
  • Save meso/135029 to your computer and use it in GitHub Desktop.
Save meso/135029 to your computer and use it in GitHub Desktop.
License: MIT
// ==UserScript==
// @name eiei
// @namespace http://www.mesolabs.com/
// @include *
// ==/UserScript==
var eiei_textarea, eiei_loadingtextarea;
var eiei_word_in2, eiei_word_in3;
var eiei_flg;
eiei_main();
function eiei_proc(targeturl) {
GM_xmlhttpRequest({
method:"GET",
url:targeturl,
onload:function(response) {
var inner = response.responseText;
if (targeturl.indexOf('www.wordwebonline.com') == -1) {
if (inner.match(/word_in2\' value=\'(.*?)\'.*word_in3\' value=\'(.*?)\'/i)) {
eiei_word_in2 = "";//RegExp.$1;
eiei_word_in3 = RegExp.$2;
}
} else if (targeturl.indexOf('www.wordwebonline.com') != -1) {
var result = unescape(escape(inner).match(/%3Cspan%20class%3D%22head%22%3E.*%3C\/ol%3E/i));
if (result != "null") {
result = result.replace(/<a.*?>/ig, '');
result = result.replace(/<\/a>/ig, '');
result = result.replace(/<ol>/ig, '<ol style="list-style: decimal outside; padding-left: 30px; margin: 10px;">');
result = result.replace(/class="head"/ig, 'style="padding-left: 10px; color: red; font-weight:bold;"');
result = result.replace(/class="key"/ig, 'style="font-weight:bold;"');
result = result.replace(/class="pron"/ig, 'class="pron" style="font-family: Times,serif;"');
result += '<div align="right">Powered by <a href="http://www.wordwebonline.com/" target="_blank">WordWeb Online</a></div>';
eiei_textarea.innerHTML = result;
} else {
eiei_textarea.innerHTML = '<div align="center"><b>Not found.</b></div><br>';
}
eiei_loadingtextarea.style.display = "none";
}
}
});
}
function eiei_main() {
eiei_flg = "";
eiei_word_in2 = "";
eiei_word_in3 = "PVawEWi72JXCKoa0Je";
var whitepng = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAQSURBVHjaYvr///9NgAADAAnfA9lUzzlRAAAAAElFTkSuQmCC)";
var closepng = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEZSURBVHjaYvz///9NBiLBs2fPGFhAjK9fvzK+efOGWV5e/g82hefPn2fj4+P79enTJwYmkMD8+fP5lICgv7+fH12xl5eXlLGxscK1a9fAhjOAnATCDg4OX0Dcvr6+FzAxT0/Pz4yMjP8TExPfnDt37iYIwzWga8KmGIQZ0T3t6OgofeDAAW4QG6j4bW5u7ltkeSZ0N3Nycv6HsQUEBP6CaKBNcHkWdA/u2LGDB2Ty5cuXOYCBIAZSHBsb+wGuCJ8HTUxMwH4qLCx8CQxahKdnzpz5HF0xSAEIgzSB5DZu3HgP7OnPnz/fBEYI4+HDh1nV1NR+IbsZaBgDKysrw6JFiwT8/f0/cXFx/WMEuvXm79+/iU0dDAABBgDVEMtQ+/4R+gAAAABJRU5ErkJggg==)";
var loading = 'url(data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAJSUlP///wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFFAAAACwAAAAAEAAQAAACJ5SPqTjte9yDQjZaLbZjawyGwUgaZCmco6myp4uqAbymrf3i8R0eBQAh+QQJFAAAACwBAAEADgAOAAACIIwvqXm42syDcbJqY7C8+9skw0hqIjmaAppi7KC+MVsAACH5BAUUAAAALAEAAQAOAA4AAAIfjC9yy8kfHFxymmrxTbz7Dw7iCAojGZ5Dqa7pyaplAQAh+QQFFAAAACwBAAEADgAOAAACIJwvEsuHypYzKcpZ7Rw57s4k4kiW5glFpxWslquaLMwUADs=)';
var eiei_area, eiei_closearea, eiei_loadingiconarea;
eiei_area = document.createElement("div");
eiei_area.setAttribute("id", "eiei");
eiei_area.setAttribute("style", "background:" + whitepng + "; border-style:dotted; border-width:1px; overflow:hidden; position:fixed; top:5px; right:5px; width:400px; height:400px; z-index:10000; display:none;");
eiei_closearea = document.createElement("div");
eiei_closearea.setAttribute("id", "eiei_close");
eiei_closearea.setAttribute("style", "background:" + closepng + "; cursor:pointer; overflow:hidden; position:absolute; top:2px; right:2px; width:12px; height:12px; z-index:10001;");
eiei_textarea = document.createElement("div");
eiei_textarea.setAttribute("id", "eiei_text");
eiei_textarea.setAttribute("style", "text-align:left; font-size: small; line-height:130%; overflow:scroll; position:absolute; top:15px; left:0px; width:100%; height:400px; z-index:10002;");
eiei_loadingtextarea = document.createElement("div");
eiei_loadingtextarea.setAttribute("id", "eiei_loading_text");
eiei_loadingtextarea.setAttribute("style", "background:" + whitepng + "; overflow:hidden; position:absolute; top:15px; left:0px; width:100%; height:400px; z-index:10003;");
eiei_loadingiconarea = document.createElement("div");
eiei_loadingiconarea.setAttribute("id", "eiei_loading_icon");
eiei_loadingiconarea.setAttribute("style", "background:" + loading + " no-repeat 50% 50%; position:absolute; width:16px; height:16px; margin:192px 192px; z-index:10004;");
var close_area = function (e) { eiei_area.style.display = "none"; }
eiei_closearea.addEventListener("click", close_area , false);
eiei_area.appendChild(eiei_closearea);
eiei_area.appendChild(eiei_textarea);
eiei_area.appendChild(eiei_loadingtextarea);
eiei_loadingtextarea.appendChild(eiei_loadingiconarea);
document.body.insertBefore(eiei_area, document.body.firstChild);
document.addEventListener('mouseup', function(){
var t = document.getSelection();
if (t != eiei_flg) {
eiei_flg = t;
if (t.match(/^[\w\d_\-\. ]+$/)){
if(eiei_word_in3) {
eiei_loadingtextarea.style.display = "block";
eiei_area.style.display = "block";
eiei_proc('http://www.wordwebonline.com/en/' + t.toUpperCase());
}
}
}
}, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment