Skip to content

Instantly share code, notes, and snippets.

@hzmangel
Created November 17, 2008 08:58
Show Gist options
  • Save hzmangel/25700 to your computer and use it in GitHub Desktop.
Save hzmangel/25700 to your computer and use it in GitHub Desktop.
undefined
CmdUtils.CreateCommand
({
name: "dictcn",
author: { name: "Hu Ziming", email: "[email protected]"},
contributors: ["Hu Ziming"],
description: "Consulting the word from <a>http://dict.cn</a>.",
help: "Consulting the word from <a>http://dict.cn</a>.",
preview: "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;padding: 2px; color: firebrick;} .trans {background-color: #2D4488; color: white; padding: 2px;} </style> <div id=\"container\"> <div id=\"word\">${w.word}</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 sent_len = rslt.find("sent").length;
var sents = new Array(sent_len);
//pblock.innerHTML = rslt.find("sent").slice(0).find("orig").text();
for (i = 0; i < sent_len; i++)
{
sents[i] = {
orig : rslt.find("sent").slice(i).find("orig").text(),
trans : rslt.find("sent").slice(i).find("trans").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 );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment