-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
136 lines (122 loc) · 3.66 KB
/
Copy pathpopup.js
File metadata and controls
136 lines (122 loc) · 3.66 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
126
127
128
129
130
131
132
133
134
135
136
// Callback on opening extension popup
window.onload = browser.extension.isAllowedIncognitoAccess().then(checkIncognito);
// 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");
// Check if the extension has access to the Private browsing mode
// Without this access, the extension will not be able to change the browser's proxy settings
function checkIncognito(isAllowed) {
if (isAllowed == false) {
warning();
} else if (isAllowed == true) {
get();
}
}
// Warn that the extension does not have the required permissions
function warning() {
let warn = document.getElementById("warn");
let header = document.getElementById("header");
let form = document.getElementById("form");
let buttons = document.getElementById("buttons");
warn.style.display = 'block';
header.style.display = 'none';
form.style.display = 'none';
buttons.style.display = 'none';
}
// Initial settings check and popup configuration
function get() {
let getting = browser.proxy.settings.get({});
getting.then((got) => {
if (got.value.proxyType == "system") {
icoOff();
} else if (got.value.proxyType == "manual") {
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 = {
proxyType: "manual",
http: proxyHost + ":" + proxyPort,
ssl: proxyHost + ":" + proxyPort,
httpProxyAll:true,
proxyDNS: false,
passthrough: passthrough
};
browser.proxy.settings.set({value: config});
icoOn();
save();
}
// Disable proxy
function disable() {
let config = {
proxyType: "system",
proxyDNS: false,
passthrough: ""
};
browser.proxy.settings.set({value: config});
icoOff();
save();
}
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() {
browser.action.setIcon({path:iconsOn});
iconPopup.src = "images/on/icon-48.png";
}
// Set icons to disabled state
function icoOff() {
browser.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() {
let getting = browser.proxy.settings.get({});
getting.then((got) => {
alert(JSON.stringify(got.value));
});
}