Created
July 18, 2011 09:18
-
-
Save shivprasad/1088985 to your computer and use it in GitHub Desktop.
A simple userscript which looks up selected word on google dictionary and alerts its meaning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google Dictionary | |
// @namespace http://byteco.de | |
// @include * | |
// ==/UserScript== | |
var t = ''; | |
function gText(e) { | |
t = (document.all) ? document.selection.createRange().text : document.getSelection(); | |
t = t.replace(/^\s+|\s+$/g,""); | |
if(t && t.indexOf(' ') == -1){ | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "http://www.google.com/dictionary/json?callback=callback&q="+t+"&sl=en&tl=en&restrict=pr%2Cde&client=te", | |
onload: function(response) { | |
var data = eval("(" + response.responseText + ")"); | |
} | |
}); | |
} | |
} | |
function callback(data,http,flag){ | |
var meaning = null; | |
try{ | |
meaning = data.primaries[0].entries[1].terms[0].text; | |
if(meaning) alert(meaning); | |
}catch(e){ | |
} | |
} | |
document.addEventListener("mouseup",gText,false); | |
Yup it was done a long time back. Google since has released it's own extension which offers similar feature - https://chrome.google.com/webstore/detail/google-dictionary-by-goog/mgijmajocgfcbeboacabfgobmjgjcoja
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just want to point out for others that this is eleven years old and no longer works. I tried to modernize it, but didn't want to put in the effort to figure out what happened to
http://www.google.com/dictionary
. It 404s. I may look into this later. Here's as far as I got: