Created
February 10, 2009 09:05
-
-
Save holin/61315 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
CmdUtils.CreateCommand({ | |
name: "dict", | |
author: { | |
name: "Hu Ziming", | |
email: "[email protected]" | |
}, | |
contributors: ["Hu Ziming", "azuwis"], | |
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_dict"] = CmdUtils.__globalObject["cmd_dict"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment