Dict

By Premshree Pillai Last update Aug 1, 2005 — Installed 1,378 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 8 posts, 7 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
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.

 
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);

  •  
    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.

     
    nitro322 Scriptwright

    Perfect! Thanks, Rick!

     
    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);
     
    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!

     
    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.

    Cross
    Presentational HTML allowed.
    Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
    We help break paragraphs and link your links.
    or cancel