Skip to content

Instantly share code, notes, and snippets.

@sealence
Created January 20, 2009 03:40
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/49305 to your computer and use it in GitHub Desktop.
Save sealence/49305 to your computer and use it in GitHub Desktop.
Ubiquity: juku
/* command "jukuu" */
CmdUtils.CreateCommand({
names: ["juku"],
icon: "http://www.jukuu.com/images/logo.ico",
homepage: "http://www.jukuu.com/",
author: { name: "Sealence", email: "sealence@gmail.com"},
license: "GPL",
description: "Search in Juku",
help: "juku: your word",
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'} ],
baseurl: "http://www.jukuu.com/search.php?q=",
execute:function(args){
var input = Utils.trim(args.object.text);
var url = this.baseurl + encodeURIComponent(input);
Utils.openUrlInBrowser(url);
},
preview: function( pblock, args ) {
var input = args.object.text;
var url = this.baseurl + encodeURIComponent(input);
jQuery.get(url, function(data){
if (!data) {return;}
var pronounce = jQuery('#Table1 td[width="70%"] table:first', data).html();
var sentences = '<br/>';
jQuery('#Table1 table[width="680"] tr.e, #Table1 table[width="680"] tr.c', data)
.each(function(key, value) {
if (key < 6) {
sentences += $(value).text() +"<br/>";
if (key%2 != 0){
sentences += "<br/>";
}
}
});
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;} \
a {font-family: arial black; font-size: large; padding: 3pt;} \
#explanation {font-size: medium; font-family: tahoma;padding:3px 0;} \
</style> \
<div id=\"container\"> \
<div id=\"word\">${w.word}</div> \
<div id=\"explanation\">${w.def}</div> \
</div>";
var foobar = {
word : pronounce,
def : sentences
};
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