| 1 | /** |
|---|
| 2 | * ==VimperatorPlugin== |
|---|
| 3 | * @name tombloo.js |
|---|
| 4 | * @description Tombloo integrate plugin |
|---|
| 5 | * @description-ja Tombloo経由で選択領域などをpostする |
|---|
| 6 | * @author Trapezoid |
|---|
| 7 | * @version 0.1d |
|---|
| 8 | * ==/VimperatorPlugin== |
|---|
| 9 | * |
|---|
| 10 | * Usage: |
|---|
| 11 | * :tombloo arg -> post by Tombloo (don't use prompt) |
|---|
| 12 | * :tombloo! arg -> post by Tombloo (use prompt) |
|---|
| 13 | * :tomblooAction arg -> execute Tombloo's action in tool menu |
|---|
| 14 | **/ |
|---|
| 15 | var TomblooService = Components.classes['@brasil.to/tombloo-service;1'].getService().wrappedJSObject; |
|---|
| 16 | function update(target,src,keys){ |
|---|
| 17 | if(keys){ |
|---|
| 18 | keys.forEach(function(key){ |
|---|
| 19 | target[key] = src[key]; |
|---|
| 20 | }); |
|---|
| 21 | } else { |
|---|
| 22 | for(let key in src) |
|---|
| 23 | target[key] = src[key]; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | return target; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | function getContext(){ |
|---|
| 30 | var doc = window.content.document; |
|---|
| 31 | var win = window.content.wrappedJSObject; |
|---|
| 32 | return update(update({ |
|---|
| 33 | document : doc, |
|---|
| 34 | window : win, |
|---|
| 35 | title : ''+doc.title || '', |
|---|
| 36 | selection : ''+win.getSelection(), |
|---|
| 37 | target : doc, |
|---|
| 38 | //event : event, |
|---|
| 39 | //mouse : mouse, |
|---|
| 40 | //menu : gContextMenu, |
|---|
| 41 | },{}),win.location); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | liberator.commands.addUserCommand(['tomblooAction'],'Execute Tombloo actions', |
|---|
| 45 | function(arg){ |
|---|
| 46 | TomblooService.Tombloo.Service.actions[arg].execute(); |
|---|
| 47 | },{ |
|---|
| 48 | completer: function(filter){ |
|---|
| 49 | var completionList = new Array(); |
|---|
| 50 | for(let name in TomblooService.Tombloo.Service.actions) |
|---|
| 51 | if(name.indexOf(filter) > -1) |
|---|
| 52 | completionList.push([name,name]); |
|---|
| 53 | return [0,completionList]; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | ); |
|---|
| 57 | |
|---|
| 58 | liberator.commands.addUserCommand(['tombloo'],'Post by Tombloo', |
|---|
| 59 | function(arg,special){ |
|---|
| 60 | TomblooService.Tombloo.Service.share(getContext(),TomblooService.Tombloo.Service.extractors[arg],special); |
|---|
| 61 | },{ |
|---|
| 62 | bang: true, |
|---|
| 63 | completer: function(filter){ |
|---|
| 64 | var completionList = new Array(); |
|---|
| 65 | var exts = TomblooService.Tombloo.Service.check(getContext()); |
|---|
| 66 | for(let i=0,l=exts.length; i < l; i++) |
|---|
| 67 | if(exts[i].name.indexOf(filter) > -1) |
|---|
| 68 | completionList.push([exts[i].name,exts[i].name]); |
|---|
| 69 | return [0,completionList]; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | ); |
|---|