-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
39 lines (34 loc) · 1.5 KB
/
options.js
File metadata and controls
39 lines (34 loc) · 1.5 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
// Saves options to storage API.
function saveOptions() {
const key = document.getElementById('apikey').value;
browser.storage.local.set({ apiKey: key });
}
// Restores select box state using the preferences stored in storage.
function restoreOptions() {
browser.storage.local.get('apiKey').then(res => {
if (res.apiKey) document.getElementById('apikey').value = res.apiKey;
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
function displayStats() {
browser.storage.local.get('towerStats').then(res => {
const stats = res.towerStats || { total: 0, avoided: 0 };
const passed = stats.total - stats.avoided;
const percent = stats.total ? Math.round((stats.avoided / stats.total) * 100) : 0;
document.getElementById('totalRequests').textContent = stats.total;
document.getElementById('passedRequests').textContent = passed;
document.getElementById('avoidedRequests').textContent = stats.avoided;
document.getElementById('percentSaved').textContent = percent + '%';
});
}
document.addEventListener('DOMContentLoaded', displayStats);
// Toggle API key visibility
document.addEventListener('DOMContentLoaded', () => {
const showCheckbox = document.getElementById('showApiKey');
showCheckbox.checked = false;
showCheckbox.addEventListener('change', () => {
const apikeyInput = document.getElementById('apikey');
apikeyInput.type = showCheckbox.checked ? 'text' : 'password';
});
});