-
Notifications
You must be signed in to change notification settings - Fork 6
/
options.js
162 lines (139 loc) · 6.71 KB
/
options.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
async function optSaveOptions() {
let isDnsBlocking = document.querySelector('input[name="dns_blocking"]:checked').value == "dns_blocking_yes";
await browser.storage.local.set({
is_dns_blocking: isDnsBlocking
});
browser.runtime.sendMessage({ type: 'setDnsBlocking', value: isDnsBlocking });
let isOnOffShown = document.querySelector('input[name="on_off_shown"]:checked').value == "on_off_shown_yes";
await browser.storage.local.set({
is_on_off_shown: isOnOffShown
});
browser.runtime.sendMessage({ type: 'setOnOffSwitchShown', value: isOnOffShown });
let isVideoBlockingDisabled = document.querySelector('input[name="is_video_blocking_disabled"]:checked').value == "is_video_blocking_disabled_yes";
await browser.storage.local.set({
is_video_blocking_disabled: isVideoBlockingDisabled
});
browser.runtime.sendMessage({ type: 'setVideoBlockingDisabled', value: isVideoBlockingDisabled });
let isSilentModeEnabled = document.querySelector('input[name="is_silent_mode_enabled"]:checked').value == "is_silent_mode_enabled_yes";
await browser.storage.local.set({
is_silent_mode_enabled: isSilentModeEnabled
});
browser.runtime.sendMessage({ type: 'setSilentModeEnabled', value: isSilentModeEnabled });
let defaultZone = document.querySelector('input[name="default_zone"]:checked').value;
await browser.storage.local.set({
default_zone: defaultZone
});
let backendSelection = document.querySelector('input[name="backend_selection"]:checked').value;
await browser.storage.local.set({
backend_selection: backendSelection
});
browser.runtime.sendMessage({ type: 'setBackendSelection', value: backendSelection });
}
function optRestoreOptions() {
console.log('OPTION: Restoring saved options');
function setCurrentDnsBlockingChoice(rawResult) {
let result = rawResult.is_dns_blocking;
console.log('OPTION: Setting DNS to ' + result);
if (result) {
document.getElementById('dns_blocking_yes').checked = true;
} else {
document.getElementById('dns_blocking_no').checked = true;
}
browser.runtime.sendMessage({ type: 'setDnsBlocking', value: result });
}
function setCurrentShowOnOffSwitchChoice(rawResult) {
let result = rawResult.is_on_off_shown;
console.log('OPTION: Setting visibility of on/off switch to ' + result);
if (result) {
document.getElementById('on_off_shown_yes').checked = true;
} else {
document.getElementById('on_off_shown_no').checked = true;
}
browser.runtime.sendMessage({ type: 'setOnOffSwitchShown', value: result });
}
function setCurrentVideoBlockingChoice(rawResult) {
let result = rawResult.is_video_blocking_disabled;
console.log('OPTION: Setting video blocking disabled switch to ' + result);
if (result) {
document.getElementById('is_video_blocking_disabled_yes').checked = true;
} else {
document.getElementById('is_video_blocking_disabled_no').checked = true;
}
browser.runtime.sendMessage({ type: 'setVideoBlockingDisabled', value: result });
}
function setCurrentSilentModeEnabledChoice(rawResult) {
let result = rawResult.is_silent_mode_enabled;
console.log('OPTION: Setting silent mode enabled switch to ' + result);
if (result) {
document.getElementById('is_silent_mode_enabled_yes').checked = true;
} else {
document.getElementById('is_silent_mode_enabled_no').checked = true;
}
browser.runtime.sendMessage({ type: 'setSilentModeEnabled', value: result });
}
function setDefaultZoneSwitchChoice(rawResult) {
let result = rawResult.default_zone;
let coercedResult = result || 'automatic';
console.log('OPTION: Setting default zone to ' + coercedResult);
document.getElementById('default_zone_' + coercedResult).checked = true;
}
function setCurrentBackendSelectionSwitchChoice(rawResult) {
let result = rawResult.backend_selection;
console.log('OPTION: Setting backend to ' + result);
let coercedResult = result || 'webgl';
document.getElementById('backend_selection_' + coercedResult).checked = true;
browser.runtime.sendMessage({ type: 'setBackendSelection', value: coercedResult });
}
function onError(error) {
console.log(`Error restoring: ${error}`);
}
let getting = browser.storage.local.get('is_dns_blocking');
getting.then(setCurrentDnsBlockingChoice, onError);
let gettingOnOffShown = browser.storage.local.get('is_on_off_shown');
gettingOnOffShown.then(setCurrentShowOnOffSwitchChoice, onError);
let gettingVideoBlocking = browser.storage.local.get('is_video_blocking_disabled');
gettingVideoBlocking.then(setCurrentVideoBlockingChoice, onError);
let gettingSilentModeEnabled = browser.storage.local.get('is_silent_mode_enabled');
gettingSilentModeEnabled.then(setCurrentSilentModeEnabledChoice, onError);
let gettingDefaultZone = browser.storage.local.get('default_zone');
gettingDefaultZone.then(setDefaultZoneSwitchChoice, onError);
let gettingBackendSelection = browser.storage.local.get('backend_selection');
gettingBackendSelection.then(setCurrentBackendSelectionSwitchChoice, onError);
}
document.addEventListener("DOMContentLoaded", optRestoreOptions);
var radios = document.forms[0].elements["dns_blocking"];
for (var i = 0, max = radios.length; i < max; i++) {
radios[i].onclick = function () {
optSaveOptions();
}
}
var radiosOnOff = document.forms[0].elements["on_off_shown"];
for (var i = 0, max = radiosOnOff.length; i < max; i++) {
radiosOnOff[i].onclick = function () {
optSaveOptions();
}
}
var radiosVideoBlockingDisabled = document.forms[0].elements["is_video_blocking_disabled"];
for (var i = 0, max = radiosVideoBlockingDisabled.length; i < max; i++) {
radiosVideoBlockingDisabled[i].onclick = function () {
optSaveOptions();
}
}
var radiosSilentModeEnabled = document.forms[0].elements["is_silent_mode_enabled"];
for (var i = 0, max = radiosSilentModeEnabled.length; i < max; i++) {
radiosSilentModeEnabled[i].onclick = function () {
optSaveOptions();
}
}
var radiosDefaultZone = document.forms[0].elements["default_zone"];
for (var i = 0, max = radiosDefaultZone.length; i < max; i++) {
radiosDefaultZone[i].onclick = function () {
optSaveOptions();
}
}
var radiosBackendSelection = document.forms[0].elements["backend_selection"];
for (var i = 0, max = radiosBackendSelection.length; i < max; i++) {
radiosBackendSelection[i].onclick = function () {
optSaveOptions();
}
}