Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created September 17, 2008 05:26
Show Gist options
  • Save Yasushi/11197 to your computer and use it in GitHub Desktop.
Save Yasushi/11197 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "excite-en-ja",
icon: "http://image.excite.co.jp/jp/favicon/lep.ico",
homepage: "http://www.excite.co.jp/world/english/",
description: "translate",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
if(input.text.length == 0) {
pblock.innerHTML = "Performs a search";
return;
}
var params={wb_lp: "ENJA", before: input.text};
jQuery.ajax({
type: "GET", url: this.homepage,
data: params,
beforeSend: function(xhr){xhr.overrideMimeType("text/html;charset=Shift_JIS");},
error: function() {displayMessage("translate error");},
success: function(data) {
var div = CmdUtils.getDocumentInsecure().createElement("div");
div.innerHTML=data;
var translatedText = jQuery("textarea[name=after]",div).text();
pblock.innerHTML="translated: " + translatedText;
}
});
},
execute: function(input) {
var params={wb_lp: "ENJA", before: input.text};
Utils.openUrlInBrowser(this.homepage + "?" + jQuery.param(params));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment