-
-
Save SIN-777/148851 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: "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", | |
takes: {"input": /.*/}, | |
preview: function (pblock, input) { | |
var pnode = jQuery(pblock); | |
var cache = this._preview_cache; | |
var word = 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("#resultArea").eq(0); | |
var sas = resultArea.find(".sas"); | |
var resultList = resultArea.find("#resultList"); | |
pnode.empty().append(sas).append(resultList); | |
cache[word] = pnode.clone(); | |
}; | |
CmdUtils.previewGet(pblock, url, null, embed_content, "html"); | |
}, | |
execute: function (input) { | |
if (input.text.length == 0) return; | |
Utils.openUrlInBrowser(this._url(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: {} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "eval", | |
icon: "chrome://ubiquity/skin/icons/favicon.ico", | |
homepage: "http://d.hatena.ne.jp/bellbind/", | |
author: {name: "bellbind", email: "[email protected]"}, | |
license: "GPL", | |
description: "evaluate script", | |
help: "evaluate script", | |
takes: {"input": /.*/}, | |
preview: function (pblock, input) { | |
var code = input.text; | |
var pnode = jQuery(pblock); | |
var pre = jQuery("<pre></pre>"); | |
pre.css({overflow: "scroll"}); | |
pre.width(450); | |
pre.height(450); | |
pre.text(this._eval(code)); | |
pnode.empty().append(pre); | |
}, | |
execute: function (input) { | |
var code = input.text; | |
CmdUtils.getWindow().alert(this._eval(code)); | |
}, | |
_eval: function (code) { | |
try { | |
return this._pp(eval(code)); | |
} catch (ex) { | |
return this._pp(ex); | |
} | |
}, | |
_pp: function (obj) { | |
return this._pplevel(obj, "", false, false, 2); | |
}, | |
_pplevel: function (obj, indent, cont, flat, level) { | |
var itop = cont ? "" : indent; | |
switch (obj) { | |
case undefined: return itop + "undefined"; | |
case null: return itop + "null"; | |
case true: return itop + "true"; | |
case false: return itop + "false"; | |
} | |
if (level === 0) return itop + "..."; | |
switch (typeof obj) { | |
case "number": return itop + obj.toString(); | |
case "string": return itop + | |
(level < 2 ? "'...'" : this._ppstr(obj)); | |
case "function": return itop + | |
(level < 2 ? "function ..." : obj.toSource().split("\n").join(indent + "\n")); | |
} | |
try { | |
var nlevel = level - 1; | |
var nflat = nlevel < 2; | |
var nindent = this._nest(indent); | |
var mindent = flat ? "": nindent; | |
var mcont = flat ? true : false; | |
var mjoin = flat ? ", " : ",\n"; | |
var sjoin = flat ? "" : "\n"; | |
switch (obj.constructor) { | |
case Array: return [ | |
itop + "[", | |
[this._pplevel(item, nindent, mcont, nflat, nlevel) | |
for each (item in obj)].join(mjoin), | |
indent + "]"].join(sjoin); | |
} | |
var keys = [k for (k in obj)].sort(); | |
var name = ""; | |
try { | |
name = "/* " + obj.constructor.name + " */ "; | |
} catch (ex) { | |
; | |
} | |
return [ | |
itop + "{" + name, | |
[mindent + this._ppstr(k) + ": " + | |
this._pplevel(obj[k], nindent, true, nflat, nlevel) | |
for each (k in keys)].join(mjoin), | |
indent + "}"].join(sjoin); | |
} catch (ex) { | |
return itop + obj.toSource(); | |
} | |
}, | |
_ppstr: function (obj) { | |
return "'" + obj.split("'").join("\\'") +"'"; | |
}, | |
_nest: function (indent) {return indent + " ";} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment