-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
36 lines (32 loc) · 1.42 KB
/
Copy pathoptions.js
File metadata and controls
36 lines (32 loc) · 1.42 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
const timeoutInput = document.getElementById("timeoutSeconds");
const folderInput = document.getElementById("downloadFolder");
const saveBtn = document.getElementById("saveBtn");
const saveStatus = document.getElementById("saveStatus");
const themeToggle = document.getElementById("themeToggle");
chrome.storage.local.get(["timeoutSeconds", "downloadFolder", "theme"], (data) => {
timeoutInput.value = data.timeoutSeconds || 90;
folderInput.value = data.downloadFolder || "SO9-Downloads";
if (data.theme === "light") document.documentElement.classList.add("light-theme");
});
saveBtn.addEventListener("click", async () => {
const timeoutSeconds = Math.max(20, Math.min(300, Number(timeoutInput.value) || 90));
const downloadFolder = normalizeFolder(folderInput.value || "SO9-Downloads");
timeoutInput.value = timeoutSeconds;
folderInput.value = downloadFolder;
await chrome.storage.local.set({ timeoutSeconds, downloadFolder });
saveStatus.textContent = "Đã lưu cài đặt.";
setTimeout(() => {
saveStatus.textContent = "";
}, 1800);
});
themeToggle.addEventListener("click", async () => {
const isLight = document.documentElement.classList.toggle("light-theme");
await chrome.storage.local.set({ theme: isLight ? "light" : "dark" });
});
function normalizeFolder(value) {
return value
.trim()
.replace(/^[\\/]+|[\\/]+$/g, "")
.replace(/[<>:"|?*]/g, "-")
.replace(/[\\/]+/g, "/") || "SO9-Downloads";
}