User:MZMcBride/wordclick.js

/* Proof of anti-concept. This sucks, don't use it.

Bite me, MZM.

if(wgAction == 'view' && wgNamespaceNumber == 0) addOnloadHook(ondblclickBuild) function ondblclickBuild { var content = document.getElementById('bodyContent') || document.getElementById('content') || document.body findTextNodes(content); appendCSS('#definediv {position:fixed;top:0;right:0;width:50%;height:50%;border:2px solid black;z-index:10;background-color:#ffffff;padding:1em;margin:2em;display:block;} .ddivclose {float:right;border:1px solid black;}'); }

function findTextNodes(obj) { var childs = 0; switch (obj.nodeType) { case(1): //tag break; case(3): //txt var txt = obj.nodeValue; var txts = txt.split(' '); obj.nodeValue = ''; for(var i=0;i<txts.length;i++) { if(txts[i].replace(/[\n\r\t\s\[\]]*/ig,) == ) continue var span = document.createElement('span'); span.className = 'dclick'; span.appendChild(document.createTextNode(' ' + txts[i] + ' ')); span.setAttribute('ondblclick','defineMe("' + txts[i] + '")'); obj.parentNode.insertBefore(span,obj); }   break; } while(obj.childNodes[childs]) { if(obj.className != 'dclick' && obj.tagName != 'A') { findTextNodes(obj.childNodes[childs]); }   childs++; } }

function defineMe(word) { var content = document.getElementById('content') || document.body var div = document.createElement('div'); div.id = 'definediv'; var close = document.createElement('a'); close.setAttribute('href','javascript:killDefdiv'); close.className = 'ddivclose'; close.appendChild(document.createTextNode('close')); div.appendChild(close) div.appendChild(document.createTextNode('The word "' + word + '" sucks. Don\'t click it.')); content.appendChild(div); }

function killDefdiv { var div = document.getElementById('definediv'); while(div.firstChild) div.removeChild(div.firstChild); div.parentNode.removeChild(div); }