Skip to content

Instantly share code, notes, and snippets.

@misuba
Created May 14, 2009 17:40
Show Gist options
  • Save misuba/111791 to your computer and use it in GitHub Desktop.
Save misuba/111791 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "lazy-link",
takes: {text: noun_arb_text},
description: "Links some text to its top hit in Google.",
_firsthit: null,
_linkFor: function(recordObj) {
return "<a href='" + recordObj.unescapedUrl + "'>" + recordObj.titleNoFormatting + "</a>";
},
preview: function(pblock, directObject) {
var searchTerm = directObject.text;
CmdUtils.previewGet("http://ajax.googleapis.com/ajax/services/search/web",
{ v: "1.0", q: directObject.text },
function(data) {
this._firsthit = data.responseData.results[0];
pblock.innerHTML = "Links some text to its top hit in Google, which seems to be:<p>" +
this._linkFor(this._firsthit) + "<br />" + this._firsthit.content;
},
"json"
);
},
execute: function(inputObject) {
//var url = "http://ajax.googleapis.com/ajax/services/search/web";
//var params = { v: "1.0", q: inputObject.text };
//jQuery.get(url, params, function(data) {
CmdUtils.setSelection(this._linkFor(this._firsthit));
//}, "text");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment