Extra caution is recommended when installing recently uploaded/updated scripts (read more)
Be sure you trust any scripts you install

Dict

Find the meaning of any word on a




Nov 10, 2006
Schlick User

Nice work! I love how it displays the definition in a tooltip. It saves the hassle of checking a word by opening a new window or tab.

 
Aug 29, 2006
sudokuteka Scriptwright

Hi:

Due to the bug of greasemonkey, it has been introduced the key word "unsafeWindow" for refering to the "window". On the lasts versions of greasemonkey this script doesn't work.

I have made a few changes to make it work.

I paste the script:

// ==UserScript==
// @name Dict
// @namespace http://premshree.org/userscripts
// @description Find the meaning of any word on a
// web page by double-clicking on it
// @include *
// ==/UserScript==

/*
* $premshree$ $2005-07-21 12:25$
*/

unsafeWindow.dict = function(e) {
d = document;
text = unsafeWindow.getSelection();
text = escape(text);
if (text != '') {
MyGM_xmlhttpRequest("http://www.onelook.com/?w="+text+"&ls=a", e.clientX+window.scrollX, e.clientY+window.scrollY);
}
GM_log('text: '+text);
}

parse = function(text, x, y) {
var text_arr = text.split("\n");
var reg_exp = /^

  • .*<\/i>:<\/b>   (.*)$/i;
    for (var i=0; i<text_arr>
    var arr = reg_exp.exec(text_arr[i]);
    if (arr) {
    meaning = arr[1].replace(/color=green/, '');
    show_meaning(meaning, x, y);
    break;
    }
    }
    }

    show_meaning = function(meaning, x, y) {
    html = meaning + ' [x]';
    if (document.getElementById('GmDict')) {
    div = document.getElementById('GmDict');
    div.innerHTML = '';
    } else {
    var div = document.createElement('DIV');
    }
    div.setAttribute('ID', 'GmDict');
    div.innerHTML = html;
    div.setAttribute('name', 'GmDict');
    div.setAttribute('style', 'position: absolute; left: '+x+'px; top: '+y+'px; border: 0px; z-Index: 999; display: block; width: 150; background: #666; border: #333 solid 1px; -moz-opacity: 0.8; color: #FFF; font-size: 12px; padding: 3px;');
    document.body.insertBefore(div, document.body.firstChild);
    }

    MyGM_xmlhttpRequest = function(url, x, y) {
    GM_xmlhttpRequest ( {
    method : "GET",
    url : url,
    onload : function (details) {
    if (details.readyState == 4) {
    parse(details.responseText, x, y);
    }
    }
    } );
    }

    unsafeWindow.document.addEventListener("dblclick", unsafeWindow.dict, true);

     
    Jan 6, 2006
    Barak Peleg User

    Is it possible to change the event instead of double clicking to ctrl-double click. I sometimes use double-clk to select a word quickly which I don't want its definition.
    Except for that its great.

     
    Oct 12, 2005
    nitro322 Scriptwright

    Perfect! Thanks, Rick!

     
    Oct 5, 2005
    Rick Fletcher Scriptwright
    This line will modify the script to do what you guys want. Add it at the bottom of the script:

    window.addEventListener("click", function() { var div = document.getElementById('GmDict'); div && div.setAttribute( "style", "display: none;" ); }, true);
     
    Oct 2, 2005
    nitro322 Scriptwright

    I'd like to second Alec's request. This is a really nice extension, but it'd be more usable, if a simple click elsewhere on the page would make the definition disappear. Other than that, though, it's great!

     
    Aug 2, 2005
    Alec_Burgess User

    It would be "nice" if a single or double-click elsewhere in the page would close the popup (or provide and [x] to close the popup. Currently you have to dbl-click on word in the margin to get it out of the way.

    You could comment on this script if you were logged in.