Skip to content

Instantly share code, notes, and snippets.

@vilterp
Created February 8, 2009 15:30
Show Gist options
  • Save vilterp/60410 to your computer and use it in GitHub Desktop.
Save vilterp/60410 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "gcal",
takes: {"expression" noun_arb_text},
description: "Uses Google Calculator to evaluate an expression",
icon: "http://www.google.com/favicon.ico/",
homepage: "http://davanum.wordpress.com/",
author: { name: "Davanum Srinivas", email: "davanum AT gmail.com"},
help: "Try it out: issue "calc 22/7 - 1".",
preview: function(pblock, statusText) {
if (statusText.text != "") {
var url = 'http://www.google.com/search?q=' + encodeURI(statusText.text).replace("+", "%2B");
jQuery.get(url, null, function(page) {
result = page.match(/<h2 class=r><font size=\+1><b>.*<\/b><\/h2>/i);
pblock.innerHTML = 'Result: <h3> ' + (result == null ? "" : result) + '</h3>';
});
}
},
execute: function(statusText) {
Utils.openUrlInBrowser('http://www.google.com/search?q=' + encodeURI(statusText.text).replace("+", "%2B"));
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment