Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.