Skip to content

Instantly share code, notes, and snippets.

@shivprasad
Created July 18, 2011 09:18
Show Gist options
  • Save shivprasad/1088985 to your computer and use it in GitHub Desktop.
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.
// ==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);
@shivprasad
Copy link
Author

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