| 1 | let PLUGIN_INFO = |
|---|
| 2 | <VimperatorPlugin> |
|---|
| 3 | <name>{NAME}</name> |
|---|
| 4 | <description>Tombloo integrate plugin</description> |
|---|
| 5 | <description lang="ja">Tombloo 統合プラグイン</description> |
|---|
| 6 | <author>Trapezoid</author> |
|---|
| 7 | <version>0.1.1</version> |
|---|
| 8 | <minVersion>2.0pre</minVersion> |
|---|
| 9 | <maxVersion>2.3</maxVersion> |
|---|
| 10 | <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tombloo.js</updateURL> |
|---|
| 11 | <detail><![CDATA[ |
|---|
| 12 | |
|---|
| 13 | == EX-COMMANDS == |
|---|
| 14 | |
|---|
| 15 | :tombloo arg: |
|---|
| 16 | post by Tombloo (don't use prompt) |
|---|
| 17 | |
|---|
| 18 | :tombloo! arg: |
|---|
| 19 | post by Tombloo (use prompt) |
|---|
| 20 | |
|---|
| 21 | :tomblooAction arg: |
|---|
| 22 | execute Tombloo's action in tool menu |
|---|
| 23 | |
|---|
| 24 | ]]></detail> |
|---|
| 25 | <detail lang="ja"><![CDATA[ |
|---|
| 26 | == EX-COMMANDS == |
|---|
| 27 | |
|---|
| 28 | :tombloo arg: |
|---|
| 29 | Tombloo を使って投稿します ( ダイアログは出てきません ) |
|---|
| 30 | |
|---|
| 31 | :tombloo! arg: |
|---|
| 32 | Tombloo を使って投稿します ( ダイアログが出てきます ) |
|---|
| 33 | |
|---|
| 34 | :tomblooAction arg: |
|---|
| 35 | ツールバーから選択できる Tombloo のメニューを実行します |
|---|
| 36 | |
|---|
| 37 | ]]></detail> |
|---|
| 38 | </VimperatorPlugin>; |
|---|
| 39 | |
|---|
| 40 | (function () { |
|---|
| 41 | |
|---|
| 42 | // ts: "T"ombloo "S"ervice |
|---|
| 43 | let tomblooService; |
|---|
| 44 | try { tomblooService = getTombloo(); } |
|---|
| 45 | catch (e) { |
|---|
| 46 | liberator.log(e.message, 0); |
|---|
| 47 | return; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | with (tomblooService) { |
|---|
| 51 | |
|---|
| 52 | commands.addUserCommand( |
|---|
| 53 | ['tomblooAction'], |
|---|
| 54 | 'Execute Tombloo actions', |
|---|
| 55 | function (args) { |
|---|
| 56 | let f = Tombloo.Service.actions[args.literalArg]; |
|---|
| 57 | (f instanceof Function) |
|---|
| 58 | ? f.execute() |
|---|
| 59 | : liberator.echoerr(args.literalArg + ' is not Tombloo Action.'); |
|---|
| 60 | }, |
|---|
| 61 | { |
|---|
| 62 | literal: 0, |
|---|
| 63 | completer: function (context) { |
|---|
| 64 | context.title = ['Tombloo Actions']; |
|---|
| 65 | |
|---|
| 66 | let names = Tombloo.Service.actions.names; |
|---|
| 67 | let candidates = [[n, n] for([, n] in Iterator(names))]; |
|---|
| 68 | context.completions = candidates.filter( |
|---|
| 69 | function ($_) this.test($_[0]), |
|---|
| 70 | new RegExp(context.filter, 'i') |
|---|
| 71 | ); |
|---|
| 72 | }, |
|---|
| 73 | } |
|---|
| 74 | ); |
|---|
| 75 | |
|---|
| 76 | commands.addUserCommand( |
|---|
| 77 | ['tombloo'], |
|---|
| 78 | 'Post by Tombloo', |
|---|
| 79 | function (args) { |
|---|
| 80 | liberator.log(args.literalArg, 0); |
|---|
| 81 | let f = Tombloo.Service.extractors[args.literalArg]; |
|---|
| 82 | (typeof f === 'object') |
|---|
| 83 | ? Tombloo.Service.share(getContext(), f, args.bang) |
|---|
| 84 | : liberator.echoerr(args.string + ' is not Tombloo command'); |
|---|
| 85 | }, |
|---|
| 86 | { |
|---|
| 87 | literal: 0, |
|---|
| 88 | bang: true, |
|---|
| 89 | completer: function (context) { |
|---|
| 90 | context.title = ['Tombloo']; |
|---|
| 91 | |
|---|
| 92 | let extensions = Tombloo.Service.check(getContext()); |
|---|
| 93 | let candidates = [[e.name, e.name] for ([, e] in Iterator(extensions))]; |
|---|
| 94 | context.completions = candidates.filter( |
|---|
| 95 | function($_) this.test($_[0]), |
|---|
| 96 | new RegExp(context.filter, 'i') |
|---|
| 97 | ); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | ); |
|---|
| 101 | |
|---|
| 102 | } // with (tomblooService) |
|---|
| 103 | |
|---|
| 104 | // helper --- |
|---|
| 105 | function getTombloo() { |
|---|
| 106 | const serviceId = '@brasil.to/tombloo-service;1'; |
|---|
| 107 | |
|---|
| 108 | if (!Cc[serviceId]) |
|---|
| 109 | throw new Error('Tombloo is not found. install from http://github.com/to/tombloo/wikis'); |
|---|
| 110 | |
|---|
| 111 | return Cc[serviceId].getService().wrappedJSObject; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | function getContext() { |
|---|
| 115 | const doc = window.content.document; |
|---|
| 116 | const win = window.content.wrappedJSObject; |
|---|
| 117 | |
|---|
| 118 | function getTarget() { |
|---|
| 119 | if (/^http:\/\/reader\.livedoor\.com/.test(buffer.URL)) { |
|---|
| 120 | let item = win.get_active_item && win.get_active_item(true); |
|---|
| 121 | return item ? item.element : doc; |
|---|
| 122 | } else { |
|---|
| 123 | return doc; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | return implant( |
|---|
| 128 | implant( |
|---|
| 129 | { |
|---|
| 130 | document: doc, |
|---|
| 131 | window: win, |
|---|
| 132 | title: doc.title.toString() || '', |
|---|
| 133 | selection: win.getSelection().toString(), |
|---|
| 134 | target: getTarget(), |
|---|
| 135 | //event : event, |
|---|
| 136 | //mouse : mouse, |
|---|
| 137 | //menu : gContextMenu, |
|---|
| 138 | }, |
|---|
| 139 | {} |
|---|
| 140 | ), |
|---|
| 141 | win.location |
|---|
| 142 | ); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | // stuff --- |
|---|
| 146 | function implant(dst, src, keys){ |
|---|
| 147 | if (keys) { |
|---|
| 148 | keys.forEach(function(key) { dst[key] = src[key]; }); |
|---|
| 149 | } |
|---|
| 150 | else { |
|---|
| 151 | for (let key in src) dst[key] = src[key]; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | return dst; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | })(); |
|---|
| 158 | |
|---|
| 159 | // vim:sw=4 ts=4 et: |
|---|