diff options
author | janus_wel | 2009-01-12 16:32:08 +0000 |
---|---|---|
committer | janus_wel | 2009-01-12 16:32:08 +0000 |
commit | 06f1822c89ff09d6b117b00f675878b51bc7c6e4 (patch) | |
tree | 5f1c2658ebf1a6458bf3c789297e9b6baa5c4e56 | |
parent | 77bcd49c4241de73e24eb0caef2355324997758f (diff) | |
download | vimperator-plugins-06f1822c89ff09d6b117b00f675878b51bc7c6e4.tar.bz2 |
refactoring
follow 2.0pre HEAD
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28342 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r-- | tombloo.js | 200 |
1 files changed, 141 insertions, 59 deletions
@@ -1,69 +1,151 @@ -/** - * ==VimperatorPlugin== - * @name tombloo.js - * @description Tombloo integrate plugin - * @description-ja Tombloo経由で選択領域などをpostする - * @author Trapezoid - * @version 0.1d - * ==/VimperatorPlugin== - * - * Usage: - * :tombloo arg -> post by Tombloo (don't use prompt) - * :tombloo! arg -> post by Tombloo (use prompt) - * :tomblooAction arg -> execute Tombloo's action in tool menu - **/ -var TomblooService = Components.classes['@brasil.to/tombloo-service;1'].getService().wrappedJSObject; -function update(target,src,keys){ - if(keys){ - keys.forEach(function(key){ - target[key] = src[key]; - }); - } else { - for(let key in src) - target[key] = src[key]; - } +let PLUGIN_INFO = +<VimperatorPlugin> +<name>{NAME}</name> +<description>Tombloo integrate plugin</description> +<description lang="ja">Tombloo 統合プラグイン</description> +<author>Trapezoid</author> +<version>0.1e</version> +<minVersion>2.0pre</minVersion> +<maxVersion>2.0pre</maxVersion> +<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tombloo.js</updateURL> +<detail><![CDATA[ - return target; -} +== EX-COMMANDS == + +:tombloo arg: + post by Tombloo (don't use prompt) + +:tombloo! arg: + post by Tombloo (use prompt) + +:tomblooAction arg: + execute Tombloo's action in tool menu + +]]></detail> +<detail lang="ja"><![CDATA[ +== EX-COMMANDS == + +:tombloo arg: + Tombloo を使って投稿します ( ダイアログは出てきません ) + +:tombloo! arg: + Tombloo を使って投稿します ( ダイアログが出てきます ) -function getContext(){ - var doc = window.content.document; - var win = window.content.wrappedJSObject; - return update(update({ - document : doc, - window : win, - title : ''+doc.title || '', - selection : ''+win.getSelection(), - target : doc, - //event : event, - //mouse : mouse, - //menu : gContextMenu, - },{}),win.location); +:tomblooAction arg: + ツールバーから選択できる Tombloo のメニューを実行します + +]]></detail> +</VimperatorPlugin>; + +(function () { + +// ts: "T"ombloo "S"ervice +let tomblooService; +try { tomblooService = getTombloo(); } +catch (e) { + liberator.log(e.message, 0); + return; } -commands.addUserCommand(['tomblooAction'],'Execute Tombloo actions', - function(arg){ - TomblooService.Tombloo.Service.actions[arg.string].execute(); - },{ - completer: function(context){ - context.title = ['Tombloo Actions']; - context.completions = [[name,name] for(name in TomblooService.Tombloo.Service.actions)].filter(function($_){ - return this.test($_[0]); - }, new RegExp(context.filter, 'i')); - } +with (tomblooService) { + +commands.addUserCommand( + ['tomblooAction'], + 'Execute Tombloo actions', + function (arg) { + let f = Tombloo.Service.actions[arg.string]; + (f instanceof Function) + ? f.execute() + : liberator.echoerr(arg.string + ' is not Tombloo Action.'); + }, + { + completer: function (context) { + context.title = ['Tombloo Actions']; + + let names = Tombloo.Service.actions.names; + let candidates = [[n, n] for([, n] in Iterator(names))]; + context.completions = candidates.filter( + function ($_) this.test($_[0]), + new RegExp(context.filter, 'i') + ); + }, } ); -commands.addUserCommand(['tombloo'],'Post by Tombloo', - function(arg,special){ - TomblooService.Tombloo.Service.share(getContext(),TomblooService.Tombloo.Service.extractors[arg.string],special); - },{ +commands.addUserCommand( + ['tombloo'], + 'Post by Tombloo', + function (args, special) { + //let f = Tombloo.Service.extractors[args.string]; + let arg = args.string.replace(/\\\u0020/g, '\u0020'); + liberator.log(args.string, 0); + liberator.log(arg, 0); + + let f = Tombloo.Service.extractors[arg]; + (typeof f === 'object') + ? Tombloo.Service.share(getContext(), f, special) + : liberator.echoerr(args.string + ' is not Tombloo command'); + }, + { bang: true, - completer: function(context){ - var completionList = new Array(); - var exts = TomblooService.Tombloo.Service.check(getContext()); - context.title = ['Tombloo']; - context.completions = [[exts[i].name, exts[i].name] for(i in exts)].filter(function($_) this.test($_[0]), new RegExp(context.filter, 'i')) - } + completer: function (context) { + context.title = ['Tombloo']; + + let extensions = Tombloo.Service.check(getContext()); + let candidates = [[e.name, e.name] for ([, e] in Iterator(extensions))]; + context.completions = candidates.filter( + function($_) this.test($_[0]), + new RegExp(context.filter, 'i') + ) + }, } ); + +} // with (tomblooService) + +// helper --- +function getTombloo() { + const serviceId = '@brasil.to/tombloo-service;1'; + + if (!Cc[serviceId]) + throw new Error('Tombloo is not found. install from http://github.com/to/tombloo/wikis'); + + return Cc[serviceId].getService().wrappedJSObject; +} + +function getContext() { + const doc = window.content.document; + const win = window.content.wrappedJSObject; + return implant( + implant( + { + document: doc, + window: win, + title: doc.title.toString() || '', + selection: win.getSelection().toString(), + target: doc, + //event : event, + //mouse : mouse, + //menu : gContextMenu, + }, + {} + ), + win.location + ); +} + +// stuff --- +function implant(dst, src, keys){ + if (keys) { + keys.forEach(function(key) { dst[key] = src[key]; }); + } + else { + for (let key in src) dst[key] = src[key]; + } + + return dst; +} + +})(); + +// vim:sw=4 ts=4 et: |