aboutsummaryrefslogtreecommitdiffstats
path: root/proxy.js
blob: 65cddbc5472bbdbf4642230b55cad36e744e55d2 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
/**
 * Vimperator plugin
 *
 * proxy setting plugin (for Vimperator 0.6pre)
 *
 * @author cho45
 * @author halt feits
 * @version 0.6
 */

(function() {

    const proxy_settings = [
        {
            conf_name: 'disable',
            conf_usage: 'direct connection',
            settings: [
                {
                    label: 'type',
                    param: 0
                }
            ]
        },
        {
            conf_name: 'polipo',
            conf_usage: 'use polipo cache proxy',
            settings: [
                {
                    label: 'type',
                    param: 1
                },
                {
                    label: 'http',
                    param: 'localhost'
                },
                {
                    label: 'http_port',
                    param: 8123
                }
            ]
        }
    ];

    liberator.commands.addUserCommand(["proxy"], 'Proxy settings', function (args) {
        const prefs = Components.classes["@mozilla.org/preferences-service;1"]
                                .getService(Components.interfaces.nsIPrefService);
        var name = args;
        if (!name) {
            liberator.echo("Usage: proxy {setting name}");
        }
        proxy_settings.some(function (proxy_setting) {
            if (proxy_setting.conf_name.toLowerCase() != name.toLowerCase()) {
                return false;
            }

            //delete setting
            ['http', 'ssl', 'ftp', 'gopher'].forEach(function (scheme_name) {
                prefs.setCharPref("network.proxy." + scheme_name, '');
                prefs.setIntPref("network.proxy." + scheme_name + "_port", 0);
            });

            proxy_setting.settings.forEach(function (conf) {
                liberator.options.setPref('network.proxy.' + conf.label, conf.param);
            });

            liberator.echo("Set config: " + name);
            return true;
        });
    },
    {
        completer: function (filter) {
            var completions = [];
            var exp = new RegExp("^" + filter);

            for each (let { conf_name: name, conf_usage: usage } in proxy_settings) {
                if (exp.test(name)) {
                    completions.push([name, usage]);
                }
            }

            return [0, completions];
        }
    });

})();
// vim: set sw=4 ts=4 et: