-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
125 lines (113 loc) · 3 KB
/
Copy pathpopup.js
File metadata and controls
125 lines (113 loc) · 3 KB
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
116
117
118
119
120
121
122
123
124
125
// Callback on opening extension popup
window.onload = get();
// Listner for 'Disable' button click
const disableBtn = document.getElementById("disableBtn");
disableBtn.addEventListener("click",() => {
disable();
});
// Listner for 'Enable' button click
const enableBtn = document.getElementById("enableBtn");
enableBtn.addEventListener("click",() => {
enable();
});
// Icon in the popup
const iconPopup = document.getElementById("icon");
// Initial settings check and popup configuration
function get() {
chrome.proxy.settings.get(
{'incognito': false},
function(config) {
if (config.value.mode == "system") {
icoOff();
} else if (config.value.mode == "fixed_servers") {
icoOn();
}
}
);
if (localStorage.getItem("proxyHost") != null
&& localStorage.getItem("proxyPort") != null
&& localStorage.getItem("passthrough") != null) {
let proxyHost = document.getElementById("proxyHost");
let proxyPort = document.getElementById("proxyPort");
let passthrough = document.getElementById("passthrough");
proxyHost.value = localStorage.getItem("proxyHost");
proxyPort.value = localStorage.getItem("proxyPort");
passthrough.value = localStorage.getItem("passthrough");
}
}
// Enable proxy
function enable() {
let proxyHost = document.getElementById("proxyHost").value;
let proxyPort = document.getElementById("proxyPort").value;
let passthrough = document.getElementById("passthrough").value;
let config = {
mode: "fixed_servers",
rules: {
singleProxy: {
host: proxyHost,
port: Number(proxyPort)
},
bypassList: [passthrough]
}
};
chrome.proxy.settings.set(
{value: config, scope: 'regular'},
function() {}
);
icoOn();
save();
}
// Disable proxy
function disable() {
let config = {
mode: "system"
};
chrome.proxy.settings.set(
{value: config, scope: 'regular'},
function() {}
);
icoOff();
save();
}
// Save current settings to localStorage
function save() {
let proxyHost = document.getElementById("proxyHost").value;
let proxyPort = document.getElementById("proxyPort").value;
let passthrough = document.getElementById("passthrough").value;
localStorage.setItem("proxyHost", proxyHost);
localStorage.setItem("proxyPort", proxyPort);
localStorage.setItem("passthrough", passthrough);
}
// Set icons to enabled state
function icoOn() {
chrome.action.setIcon({path:iconsOn});
iconPopup.src = "images/on/icon-48.png";
}
// Set icons to disabled state
function icoOff() {
chrome.action.setIcon({path:iconsOff});
iconPopup.src = "images/icon-48.png"
}
// Icons path object for enabled state
iconsOn = {
"16":"images/on/icon-16.png",
"32":"images/on/icon-32.png",
"48":"images/on/icon-48.png",
"128":"images/on/icon-128.png"
}
// Icons path object for disabled state
iconsOff = {
"16":"images/icon-16.png",
"32":"images/icon-32.png",
"48":"images/icon-48.png",
"128":"images/icon-128.png"
}
// Show current settings JSON
function show() {
chrome.proxy.settings.get(
{'incognito': false},
function(config) {
alert(JSON.stringify(config));
}
);
}