Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment