From 06f1822c89ff09d6b117b00f675878b51bc7c6e4 Mon Sep 17 00:00:00 2001 From: janus_wel Date: Mon, 12 Jan 2009 16:32:08 +0000 Subject: refactoring follow 2.0pre HEAD git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28342 d0d07461-0603-4401-acd4-de1884942a52 --- tombloo.js | 200 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 141 insertions(+), 59 deletions(-) (limited to 'tombloo.js') diff --git a/tombloo.js b/tombloo.js index e0ca491..323b494 100644 --- a/tombloo.js +++ b/tombloo.js @@ -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 = + +{NAME} +Tombloo integrate plugin +Tombloo 統合プラグイン +Trapezoid +0.1e +2.0pre +2.0pre +http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tombloo.js + + +; + +(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: -- cgit v1.2.3