User:Conrad.Irwin/monobook.js

// Original code and ideas en:wiktionary:User:Bequw // Modifications and fixes en:wiktionary:User:Conrad.Irwin setTimeout(function { var goInline=false; var mozilla=false; if (document.all == null && document.getElementById != null && document.layers == null) {        mozilla = true;        document.addEventListener("dblclick", function (e) { window.event = e;}, true); } function FindWord {        if (!mozilla && window.event && document && document.body) {                if (document.readyState != "complete") return false;                //IE                var my_range = document.selection.createRange;                my_range.collapse;                my_range.expand("word");                LookupWord(my_range.text);                event.returnValue = false;                return false;        }        else if (event.rangeParent && event.rangeParent.nodeType == document.TEXT_NODE) {                //mozilla part

if (document.getSelection && document.getSelection) { return LookupWord(document.getSelection); }               var rangeOffset = event.rangeOffset; var range = document.createRange; range.selectNode(event.rangeParent); var my_rangestr = range.toString; range.detach; // which word the rangeOffset is in               var wordlist1 = my_rangestr.substring(0, rangeOffset).split(/\s+/); var wordlist2 = my_rangestr.substring(rangeOffset, my_rangestr.length).split(/\s+/); if (my_rangestr.length > 0) { LookupWord(wordlist1[wordlist1.length - 1]+wordlist2[0]); }               event.preventDefault; event.stopPropagation; } }   function ExtractWord(s) {

// Should be good enough for French and English - full unicode regex is infeasable in JS. s = s.replace(/^[^a-zàâçéèêëîïôûùüÿÀÂÇÉÈÊËÎÏÔÛÙÜŸ]+/i, "").replace(/[^a-zàâçéèêëîïôûùüÿÀÂÇÉÈÊËÎÏÔÛÙÜŸ]+$/i, "")

return s;   } function LookupWord(s) { var newurl = "http://en.wiktionary.org/wiki/" + ExtractWord(s); var newwin = window.open(newurl,'temp','height=450,width=800,location,menubar,toolbar,status,resizable,scrollbars'); if (newwin) newwin.focus; }   if (document.addEventListener) { document.addEventListener("dblclick", FindWord, true); } else if (document.all) { document.ondblclick = FindWord; }

}, 1000);