aboutsummaryrefslogtreecommitdiffstats
path: root/proxy.js
blob: 134c40d59f57d3366a6f89186b882f59fc4f6555 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
 * vimperator plugin
 *
 * proxy setting plugin (for vimperator-0.6pre)
 *
 * @author cho45
 * @author halt feits
 * @version 0.6.0
 */

(function() {

    const proxy_settings = [
    {
        conf_name: 'disable',
        setting: [
            {
                label: 'network.proxy.type',
                param: 0
            }
        ]
    },
    {
        conf_name: 'polipo',
        setting: [
            {
                label: 'network.proxy.type',
                param: 1
            },
            {
                label: 'network.proxy.http',
                param: 'localhost'
            },
            {
                label: 'network.proxy.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}");
        }
        for (var i = 0; i < proxy_settings.length; i++) {
            if (proxy_settings[i].conf_name.toLowerCase() == name.toLowerCase()) {

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

                for (var j = 0; j < proxy_settings[i].setting.length; j++) {

                    var conf = proxy_settings[i].setting[j];
                    switch (conf.label) {
                        case "network.proxy.type":
                            prefs.setIntPref(conf.label, conf.param);
                            break;
                        case "network.proxy.http":
                            prefs.setCharPref(conf.label, conf.param);
                            break;
                        case "network.proxy.http_port":
                            prefs.setIntPref(conf.label, conf.param);
                            break;
                    }
                
                }

                liberator.echo("set config:" + name);
                break;
            }
        }
    },
    {
        completer: function (filter) {
            var completions = [];

            for (var i = 0; i < proxy_settings.length; i++) {
                name = proxy_settings[i].conf_name;
                
                var exp = new RegExp("^" + filter);

                if (exp.test(name)) {
                    completions.push([name, name]);
                }
            }

            return [0, completions];
        }
    }
);

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