aboutsummaryrefslogtreecommitdiffstats
path: root/googlekanji.js
diff options
context:
space:
mode:
authoranekos2008-07-25 08:23:56 +0000
committeranekos2008-07-25 08:23:56 +0000
commit88a411faf720d4387a13cccce344eee767a28762 (patch)
tree88d48c8fb9ecaa3c4449efd7dba6fa9c8aaf016f /googlekanji.js
parent2bac9a98f22fca224f1b4a4407457feb8524381f (diff)
downloadvimperator-plugins-88a411faf720d4387a13cccce344eee767a28762.tar.bz2
added
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@16415 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'googlekanji.js')
-rw-r--r--googlekanji.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/googlekanji.js b/googlekanji.js
new file mode 100644
index 0000000..56eb5c9
--- /dev/null
+++ b/googlekanji.js
@@ -0,0 +1,93 @@
+// ==VimperatorPlugin==
+// @name Google-Kanji
+// @description-ja グーグルを使って漢字を検索
+// @license Creative Commons 2.1 (Attribution + Share Alike)
+// @version 1.0
+// ==/VimperatorPlugin==
+//
+// Usage:
+// :gkanji うぶめ
+// のようにひらがななどで読みを入力します。
+// すると、
+// :gkcopy
+// が開き、補完が可能になるので、正しそうな漢字を選びます。
+// すると、クリップボードにその漢字がコピーされます。
+
+(function () { try{
+
+ var copycompl = [];
+
+ function getKanji (word) {
+ var re = /[一-龠]+/g;
+ var ignore = /検索|関連/;
+ var spaces = /^\s+$/;
+ var req = new XMLHttpRequest();
+ var word = encodeURIComponent(word);
+ liberator.log(word);
+ req.open('GET', 'http://www.google.co.jp/search?hl=ja&q=' + word + '&lr=lang_ja', true);
+ var f = function () {
+ var cnt = {};
+ for each (var it in req.responseText.match(re)) {
+ if (!it.match || it.match(ignore))
+ continue;
+ if (cnt[it])
+ cnt[it] += 1;
+ else
+ cnt[it] = 1;
+ }
+ var cnta = [];
+ for (var i in cnt) {
+ if (cnt[i] < 3)
+ continue;
+ cnta.push([i, cnt[i]]);
+ }
+ cnta.sort(function (a, b) b[1] - a[1]);
+ copycompl = cnta;
+ liberator.commandline.open(":", "gkcopy ", liberator.modes.EX);
+ };
+ req.onreadystatechange = function (aEvt) {
+ if (req.readyState == 4) {
+ if(req.status == 200) {
+ f();
+ }
+ }
+ };
+ req.send(null);
+ }
+
+ liberator.commands.addUserCommand(
+ ['gkanji', 'googlekanji'],
+ 'google kanji',
+ function (word) {
+ getKanji(word);
+ }
+ );
+
+ function copyToClipboard (copytext) {
+ const supstr = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
+ const trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
+ const clipid = Ci.nsIClipboard;
+ const clip = Cc["@mozilla.org/widget/clipboard;1"].getService(clipid);
+
+ supstr.data = copytext;
+ trans.addDataFlavor("text/unicode");
+ trans.setTransferData("text/unicode", supstr, copytext.length * 2);
+
+ clip.setData(trans, null, clipid.kGlobalClipboard);
+ }
+
+ liberator.commands.addUserCommand(
+ ['gkcopy'],
+ 'google kanji',
+ function (word) {
+ copyToClipboard(word);
+ },
+ {
+ completer: function (args) {
+ return [0, copycompl];
+ }
+ }
+ );
+
+
+}catch(e){liberator.log(e)}})();