Skip to content

Instantly share code, notes, and snippets.

@azuwis
Created November 17, 2008 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save azuwis/25701 to your computer and use it in GitHub Desktop.
Save azuwis/25701 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "dictcn",
author: {
name: "Hu Ziming",
email: "hzmangel@gmail.com"
},
contributors: ["Hu Ziming"],
icon : "http://dict.cn/favicon.ico",
description: "Consulting the word from <a>http://dict.cn</a>.",
help: "Consulting the word from <a>http://dict.cn</a>.",
takes: {
"eng_word": noun_arb_text
},
license: "MPL",
preview: function( pblock, direct_obj){
var eng_word = direct_obj.text;
var url = "http://dict.cn/ws.php?q=";
url += eng_word;
var pre_template = "<style> #container {background-color: #73bFE6;} #word {font-family: arial black; color: maroon;font-size: x-large;} #explanation {color: midnightblue; font-size: medium; font-family: tahoma;padding:3px;} #sent {color: maroon;} .orig {background-color: #B6C5F2; margin: 1px 0; color: firebrick;} .trans {background-color: #2D4488; color: white; margin: 1px 0;} </style> <div id=\"container\"> <div id=\"word\">${w.word} (${w.prons})</div> <div id=\"explanation\">${w.def}</div>{for foo in w.sents}<div id=\"sent\"> <div class=\"orig\">${foo.orig}</div> <div class=\"trans\">${foo.trans}</div> </div> </div>{/for}";
jQuery.get(url, function(data){
var rslt = jQuery(data).find("dict");
var sents = rslt.find("sent").map(function(){
return {
orig : jQuery("orig", this).text(),
trans : jQuery("trans", this).text()
}
});
var foobar = {
word : rslt.find("key").text(),
prons : rslt.find("pron").text(),
def : rslt.find("def").text(),
sents : sents
};
pblock.innerHTML = CmdUtils.renderTemplate(pre_template, {
w:foobar
});
}, "xml");
},
execute: function( direct_obj ){
var eng_word = direct_obj.text;
var url = "http://dict.cn/";
url += eng_word;
Utils.openUrlInBrowser( url );
}
});
CmdUtils.__globalObject["cmd_dcn"] = CmdUtils.__globalObject["cmd_dictcn"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment