let PLUGIN_INFO =
{NAME}
Tombloo integrate plugin
Tombloo 統合プラグイン
Trapezoid
0.1.1
2.0pre
2.3
https://github.com/vimpr/vimperator-plugins/raw/master/tombloo.js
;
(function () {
// ts: "T"ombloo "S"ervice
let tomblooService;
try { tomblooService = getTombloo(); }
catch (e) {
liberator.log(e.message, 0);
return;
}
with (tomblooService) {
commands.addUserCommand(
['tomblooAction'],
'Execute Tombloo actions',
function (args) {
let f = Tombloo.Service.actions[args.literalArg];
(f instanceof Function)
? f.execute()
: liberator.echoerr(args.literalArg + ' is not Tombloo Action.');
},
{
literal: 0,
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 (args) {
liberator.log(args.literalArg, 0);
let f = Tombloo.Service.extractors[args.literalArg];
(typeof f === 'object')
? Tombloo.Service.share(getContext(), f, args.bang)
: liberator.echoerr(args.string + ' is not Tombloo command');
},
{
literal: 0,
bang: true,
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;
function getTarget() {
if (/^http:\/\/reader\.livedoor\.com/.test(buffer.URL)) {
let item = win.get_active_item && win.get_active_item(true);
return item ? item.element : doc;
} else {
return doc;
}
}
return implant(
implant(
{
document: doc,
window: win,
title: doc.title.toString() || '',
selection: win.getSelection().toString(),
target: getTarget(),
//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:
f='#n11'>11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|