root/lang/javascript/vimperator-plugins/trunk/hint-tombloo.js

Revision 34009, 2.0 kB (checked in by motemen, 15 months ago)

hint-tombloo.js

Line 
1var PLUGIN_INFO =
2<VimperatorPlugin>
3<name>{NAME}</name>
4<description>Hint mode for Tombloo</description>
5<author>motemen</author>
6<version>0.1</version>
7<minVersion>2.0pre</minVersion>
8<maxVersion>2.0pre</maxVersion>
9<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/hint-tombloo.js</updateURL>
10<detail><![CDATA[
11== SETTINGS ==
12
13let g:hint_tombloo_key   = 'R'
14let g:hint_tombloo_xpath = '//img'
15
16== MAPPINGS ==
17;R :
18    Share target element by Tombloo
19
20]]></detail>
21</VimperatorPlugin>;
22
23(function () {
24
25var hintKey   = liberator.globalVariables.hint_tombloo_key   || 'R';
26var hintXPath = liberator.globalVariables.hint_tombloo_xpath || '//img';
27
28hints.addMode(
29    hintKey,
30    'Share by Tombloo',
31    function (elem) {
32        var tomblooService = Cc['@brasil.to/tombloo-service;1'].getService().wrappedJSObject.Tombloo.Service;
33
34        var d = window.content.document;
35        var w = window.content.wrappedJSObject;
36        var context = {
37            document: d,
38            window:   w,
39            title:    d.title,
40            target:   elem,
41        };
42        for (let p in w.location) {
43            context[p] = w.location[p];
44        }
45
46        var extractors = tomblooService.check(context);
47
48        liberator.modules.commandline.input(
49            'Extractor: ',
50            function (string) {
51                var extractor;
52                for (let i = 0; i < extractors.length; i++) {
53                    if (extractors[i].name == string) {
54                        extractor = extractors[i];
55                        break;
56                    }
57                }
58                if (!extractor) return;
59
60                tomblooService.share(context, extractor, true);
61            },
62            {
63                completer: function (context) {
64                    context.title = ['Tombloo Extractors'];
65                    context.completions = extractors.map(
66                        function (_) [ _.name, _.name ]
67                    );
68                }
69            }
70        );
71    },
72    function () hintXPath
73);
74
75})();
Note: See TracBrowser for help on using the browser.