Skip to content

Instantly share code, notes, and snippets.

@haohaolee
Forked from sealence/cambridge.js
Created April 7, 2010 03:07
Show Gist options
  • Save haohaolee/358464 to your computer and use it in GitHub Desktop.
Save haohaolee/358464 to your computer and use it in GitHub Desktop.
/* 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: "[email protected]"},
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(/chrome\:\/\/ubiquity/g, "");
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