Skip to content

Instantly share code, notes, and snippets.

@sealence
Created November 28, 2010 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sealence/718941 to your computer and use it in GitHub Desktop.
Save sealence/718941 to your computer and use it in GitHub Desktop.
Ubiquity:iciba
CmdUtils.CreateCommand({
names: ["iciba"],
description: "A short description of your command.",
help: "How to use your command.",
author: {
name: "sealence",
email: "sealence@gmail.com",
homepage: "http://labs.mozilla.com/",
},
license: "GPL",
homepage: "http://ubiquity.mozilla.com/",
icon: "http://www.iciba.com/favicon.ico",
arguments: [{role: "object", nountype: noun_arb_text, label: "text"}],
baseurl: "http://www.iciba.com/",
execute: function execute(args) {
var input = Utils.trim(args.object.text);
var url = this.baseurl + encodeURIComponent(input);
Utils.openUrlInBrowser(url);
},
preview: function preview(pblock, args) {
var input = args.object.text;
var url = this.baseurl + encodeURIComponent(input);
jQuery.get(url, function(data){
if (!data) {return;}
var word = jQuery('#word_name', data).text();
var prons = jQuery('#word_top span:not(.font_black.marginleft5)', data).text();
var def = jQuery('#sentence_open', data).html();
var pre_template = "\
<style> \
#container {background-color: #595A5F; margin: 10pt; padding 5pt;} \
#word {background-color: #3399CC; font-family: arial black; font-size: x-large; padding: 3pt;} \
#explanation {font-size: medium; font-family: tahoma;padding:3px 0;} \
</style> \
<div id=\"container\"> \
<div id=\"word\">${w.word} (${w.prons})</div> \
<div id=\"explanation\">${w.def}</div> \
</div>";
var foobar = {
word : word,
prons : prons,
def : def
};
pblock.innerHTML = CmdUtils.renderTemplate(pre_template, {
w:foobar
});
});
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment