-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.js
More file actions
52 lines (46 loc) · 1.46 KB
/
Copy pathoptions.js
File metadata and controls
52 lines (46 loc) · 1.46 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
const concurrencyInputEl = document.getElementById("concurrency-input");
const saveButtonEl = document.getElementById("save-button");
const statusEl = document.getElementById("status");
function clampConcurrency(value) {
const n = Number(value);
if (!Number.isFinite(n) || n <= 0) return 5;
return Math.max(1, Math.min(20, Math.round(n)));
}
function loadSettings() {
chrome.runtime.sendMessage({ type: "get_settings" }, (response) => {
if (!response || !response.ok) {
statusEl.textContent =
response?.error ||
chrome.runtime.lastError?.message ||
"Failed to load settings.";
return;
}
const n = response.settings?.concurrency ?? 5;
concurrencyInputEl.value = n;
statusEl.textContent = "";
});
}
saveButtonEl.addEventListener("click", () => {
const desired = clampConcurrency(concurrencyInputEl.value);
chrome.runtime.sendMessage(
{
type: "save_settings",
settings: { concurrency: desired }
},
(response) => {
if (!response || !response.ok) {
statusEl.textContent =
response?.error ||
chrome.runtime.lastError?.message ||
"Failed to save settings.";
return;
}
concurrencyInputEl.value = response.settings?.concurrency ?? desired;
statusEl.textContent = "Settings saved.";
setTimeout(() => {
statusEl.textContent = "";
}, 2000);
}
);
});
document.addEventListener("DOMContentLoaded", loadSettings);