-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoggleproxy.js
115 lines (101 loc) · 3.06 KB
/
toggleproxy.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
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
/* toggleproxy -- Pentadactyl plugin for switching the proxy settings
* in a flash. See embedded documentation for more.
*
* Installation:
* Copy the .js and .penta (optional) files to ~/.pentadactyl/plugins/
*
* Copyright:
* Copyright (c) 2013-2014, Cong Ma <[email protected]> & Contributors
* All rights reserved.
*
* License:
* BSD license <http://opensource.org/licenses/BSD-2-Clause>
*/
/*
* FIXME: Add more supported proxy types and settings.
*/
"use strict";
/* Plugin manifest */
var INFO =
["plugin", {
"name": "toggleproxy",
"version": "0.2",
"href": "https://github.com/congma/toggleproxy",
"summary": "toggleproxy - switching proxy settings in a flash",
"xmlns": "dactyl"},
["author", {
"email": "[email protected]",
"href": "https://cma.lamost.org/"}, "Cong Ma"],
["license", {"href": "http://opensource.org/licenses/BSD-2-Clause"},
"BSD License"],
["project", {"name": "Pentadactyl", "min-version": "1.0" }],
["p", {},
"The ", ["str", {}, "toggleproxy"], " plugin implements the ",
["str", {}, ":toggleproxy"],
" command that turns the manual proxy setting on and off in Firefox.",
" In addition, the ", ["str", {}, ":showproxy"], " command returns",
" the current proxy status. SOCKS proxy port number can be set",
" using the ", ["str", {}, ":sxportnum"], " command."],
["item", {},
["tags", {}, ":spx :showproxy"],
["strut", {}],
["spec", {}, ":showproxy"],
["description", {},
["p", {}, "Display the current proxy setting."]]],
["item", {},
["tags", {}, ":tpx :toggleproxy"],
["strut", {}],
["spec", {}, ":toggleproxy"],
["description", {},
["p", {},
"Toggle the current manual proxy setting."],
["p", {},
"By default, this command is mapped to",
" the key combo ", ["str", {}, ["k", {"name": "Leader"}], "p"],
":"],
["code", {},
["ex", {}, ":nmap"], " ", ["k", {"name": "Leader"}],
"p ", ["ex", {}, ":toggleproxy"], ["k", {"name": "CR"}]]]],
["item", {},
["tags", {}, ":spn :sxportnum"],
["strut", {}],
["spec", {}, ":sxportnum ", ["a", {}, "port"]],
["description", {},
["p", {}, "Set the SOCKS port number."],
["example", {}, ["ex", {}, ":spn 9274"]]]]];
function show_proxy()
{
return dactyl.echo("proxy: " + prefs.get("network.proxy.type"));
}
function toggle_manual_proxy()
{
var proxtype = prefs.get("network.proxy.type");
if ( proxtype == 0 )
prefs.set("network.proxy.type", 1);
else
prefs.set("network.proxy.type", 0);
return show_proxy();
}
function set_socks_port(portn)
{
var x = parseInt(portn);
if ( isNaN(x) || x < 0 || x > 65535 )
return dactyl.echoerr("Error: invalid port number.");
else
return prefs.set("network.proxy.socks_port", x);
}
group.commands.add(["showproxy", "spx"],
"Display the current proxy setting.",
show_proxy,
{argCount: "0"},
true);
group.commands.add(["toggleproxy", "tpx"],
"Toggle the current manual proxy setting.",
toggle_manual_proxy,
{argCount: "0"},
true);
group.commands.add(["sxportnum", "spn"],
"Set the SOCKS port number.",
set_socks_port,
{argCount: "1"},
true);