A ubiquity command that searchs google with the prefix '"define:"
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
CmdUtils.makeSearchCommand({ | |
names: ["gdefine"], | |
url: "http://www.google.com/search?defl=en&q=define:{QUERY}", | |
icon: "http://www.google.com/favicon.ico", | |
description: "Searches Google for your words using the 'define' command.", | |
author: {name: "Isac Sacchi e Souza", email: "isacssouza@gmail.com"}, | |
license: "Public domain", | |
arguments: [{role: "object", nountype: noun_arb_text, label: "The word to define."}], | |
preview: function(pblock, args) { | |
var searchTerm = args.object.text; // The word to define | |
if(searchTerm.length < 1) { | |
// Set the default text to show when there is nothing to define | |
pblock.innerHTML = "Searches Google for your words using the 'define:' operator."; | |
return; | |
} | |
var defineSearch = "define"+encodeURIComponent(':')+searchTerm; | |
/* | |
* I set the language to English so there are more and better results. | |
* Maybe I should use the browser language or something else to set the | |
* user language. | |
*/ | |
var url = "http://www.google.com/search?defl=en&q="+defineSearch; | |
// Get the results, parse and show. | |
CmdUtils.previewGet( pblock, url, null, function(data) { | |
var resultDivPos = data.indexOf("ssb", 0); // ssb is the class of the results list. | |
var beginPos = data.indexOf("<ul", resultDivPos); // get the begin index of the list. | |
var endPos = data.indexOf("</ul>", beginPos); // get the end index of the list. | |
// Display the results as an HTML list. | |
pblock.innerHTML = "<p>Definitions of <b>"+searchTerm+"</b> on the Web:</p>"+data.substring(beginPos, endPos); | |
}); | |
}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment