-
-
Save haohaolee/358464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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