-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhint-tombloo.js
75 lines (64 loc) · 2.03 KB
/
hint-tombloo.js
1
2
3
4
5
6
7
8
9
10
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
var PLUGIN_INFO =
<VimperatorPlugin>
<name>{NAME}</name>
<description>Hint mode for Tombloo</description>
<author>motemen</author>
<version>0.1</version>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/hint-tombloo.js</updateURL>
<detail><![CDATA[
== SETTINGS ==
let g:hint_tombloo_key = 'R'
let g:hint_tombloo_xpath = '//img'
== MAPPINGS ==
;R :
Share target element by Tombloo
]]></detail>
</VimperatorPlugin>;
(function () {
var hintKey = liberator.globalVariables.hint_tombloo_key || 'R';
var hintXPath = liberator.globalVariables.hint_tombloo_xpath || '//img';
hints.addMode(
hintKey,
'Share by Tombloo',
function (elem) {
var tomblooService = Cc['@brasil.to/tombloo-service;1'].getService().wrappedJSObject.Tombloo.Service;
var d = window.content.document;
var w = window.content.wrappedJSObject;
var context = {
document: d,
window: w,
title: d.title,
target: elem,
};
for (let p in w.location) {
context[p] = w.location[p];
}
var extractors = tomblooService.check(context);
liberator.modules.commandline.input(
'Extractor: ',
function (string) {
var extractor;
for (let i = 0; i < extractors.length; i++) {
if (extractors[i].name == string) {
extractor = extractors[i];
break;
}
}
if (!extractor) return;
tomblooService.share(context, extractor, true);
},
{
completer: function (context) {
context.title = ['Tombloo Extractors'];
context.completions = extractors.map(
function (_) [ _.name, _.name ]
);
}
}
);
},
function () hintXPath
);
})();