-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
76 lines (62 loc) · 1.77 KB
/
script.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
let state = localStorage.getItem('state');
if (state === null) {
state = "Connected";
}
let over = false;
function syncState() {
const button = document.getElementById("button");
const text = document.getElementById("text");
if (state === "Disconnected") {
text.innerHTML = "Disconnected";
if (over) {
button.style.backgroundColor = "#b11f16";
} else {
button.style.backgroundColor = "#cf241a";
}
} else {
text.innerHTML = "Connected";
if (over) {
button.style.backgroundColor = "#19be00";
} else {
button.style.backgroundColor = "#1ccf00";
}
}
}
function changeState() {
const button = document.getElementById("button");
if (state === "Connected") {
state = "Disconnected";
chrome.proxy.settings.set({value: {mode: "direct"}, scope: "regular"}, function() {});
} else {
state = "Connected";
const proxyConfig = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "localhost",
port: 8080
}
}
}
chrome.proxy.settings.set(
{value: proxyConfig, scope: 'regular'},
function() {}
);
}
syncState();
localStorage.setItem('state', state);
}
window.onload = function() {
syncState();
const button = document.getElementById("button");
button.addEventListener("click", changeState);
}
document.getElementById("button").addEventListener('mouseover', (event) => {
over = true;
syncState();
});
document.getElementById("button").addEventListener('mouseout', (event) => {
over = false;
syncState();
});