One of the suggested commands was a site search in google (ie
site:
slashdot.org apple), it seemed to me a little strange to have two
commands for this, and not quite in line with the whole natural
language thing. So I made this update to the google command, so that
you can do something like:
google
slashdot.org for apple and it will do a google search like:
site:
slashdot.org apple
Any suggestions would be welcome... The only thing I can think of to
make it better would be to detect if the first argument is a domain
name, so that it would cut down on "errors", where a person actually
was using the word for in a google search.
CmdUtils.CreateCommand({
name: "google",
icon: "
http://www.google.com/favicon.ico",
searchURL: "
http://www.google.com/search?hl=en&q=",
description: "Searches Google for your words.",
takes: {"site_or_keywords": noun_arb_text},
modifiers: {"for": noun_arb_text},
execute: function(site_or_keywords, modifiers)
{
var query = this.buildQuery(site_or_keywords,modifiers);
Utils.openUrlInBrowser( this.searchURL + query );
},
preview: function(pblock, site_or_keywords, modifiers) {
var query = this.buildQuery(site_or_keywords,modifiers);
var pTemplate = "Searches Google for <b>${query}</b>";
var pData = {query: query };
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);
var url = "
http://ajax.googleapis.com/ajax/services/search/web";
var params = { v: "1.0", q: query };
jQuery.get( url, params, function(data) {
var numToDisplay = 3;
var results = data.responseData.results.splice( 0, numToDisplay );
pblock.innerHTML = CmdUtils.renderTemplate( {file:"google-
search.html"},{results:results} ); }, "json");
},
buildQuery: function(site_or_keywords, modifiers)
{
if(modifiers.for.text) { return 'site:' + site_or_keywords.text + '
' + modifiers.for.text; }
else { return site_or_keywords.text; }
},
});