-
-
Save monjudoh/392040 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
/* | |
* 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: "[email protected]"}, | |
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