User:Bequw/quickLookup.js

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 { //only do this in NS0 - substring out the "http://en.wiktionary.org" if(location.href.substring(24).indexOf(':') >= 0){return; }

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 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 LookupWord(s) { var newurl = "http://en.wiktionary.org/wiki/" + s;		if (goInline)location.href = newurl; else{ 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; }