Skip to content

Instantly share code, notes, and snippets.

@sealence
Created February 16, 2009 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sealence/65093 to your computer and use it in GitHub Desktop.
Save sealence/65093 to your computer and use it in GitHub Desktop.
Ubiquity: cambridge
/* command "cambridge" */
CmdUtils.CreateCommand({
names: ["cambridge"],
icon: "http://www.cambridge.org/assets/common/favicon/favicon.ico",
homepage: "http://dictionary.cambridge.org",
author: { name: "Sealence", email: "sealence@gmail.com"},
license: "GPL",
description: "Search in Cambridge",
help: "cambridge: your word",
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'} ],
baseurl: "http://dictionary.cambridge.org/results.asp?searchword=",
execute:function(args){
var input = Utils.trim(args.object.text);
var url = this.baseurl + encodeURIComponent(input);
Utils.openUrlInBrowser(url);
},
preview: function( pblock, args ) {
var input = args.object.text;
var url = this.baseurl + encodeURIComponent(input);
var apiUrl = "http://dictionary.cambridge.org/define.asp";
Utils.parseRemoteDocument(
url, // URL
null, // post data
function(doc) { // success callback
var data = jQuery('#main_column > :not(#search , #promo)', doc);
var result = "";
jQuery.each(data , function(i, val) {
if (val.innerHTML != "" )
result += val.innerHTML + "<br/>";
});
result = result.replace(/define.asp/g, apiUrl);
pblock.innerHTML = result;//data;
},
function() { // error callback
pblock.innerHTML = "Error!";
}
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment