User:Bequw/quickLookup.js
Jump to navigation
Jump to search
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
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;
}