Skip to content

Instantly share code, notes, and snippets.

@monjudoh
Forked from bellbind/ubiquity-alc.js
Created May 6, 2010 11:47
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 monjudoh/392040 to your computer and use it in GitHub Desktop.
Save monjudoh/392040 to your computer and use it in GitHub Desktop.
/*
* for Ubiquity 0.5
*/
CmdUtils.CreateCommand({
names: ["alc"],
icon: "http://www.alc.co.jp/favicon.ico",
homepage: "http://d.hatena.ne.jp/bellbind/",
author: {name: "bellbind", email: "bellbind@gmail.com"},
license: "GPL",
description: [
"translate word by alc/eijiro",
"input command e.g.: ",
" alc word",
"or: ",
" alc 単語"].join("\n"),
help: "translate word by alc/eijiro",
arguments: [{role:"input", nountype: noun_arb_text}],
preview: function (pblock, args) {
var pnode = jQuery(pblock);
var cache = this._preview_cache;
var word = args.input.text;
if (cache[word]) {
pnode.html(cache[word].html());
return;
}
if (word.length == 0) {
pnode.html("<pre>" + this.description + "</pre>");
cache[word] = pnode.clone();
return;
}
var url = this._url(word);
var embed_content = function (data) {
var resultArea = jQuery(data).find("#resultsArea").eq(0);
var sas = resultArea.find(".sas");
var resultList = resultArea.find("#resultsList");
pnode.empty().append(sas).append(resultList);
cache[word] = pnode.clone();
};
CmdUtils.previewGet(pblock, url, null, embed_content, "html");
},
execute: function (args) {
if (input.text.length == 0) return;
Utils.openUrlInBrowser(this._url(args.input.text));
},
_url: function (word) {
var template = "http://eow.alc.co.jp/${word}/UTF-8?ref=sa";
return CmdUtils.renderTemplate(template, {word: encodeURI(word)});
},
_preview_cache: {}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment