-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.js
More file actions
25 lines (19 loc) · 783 Bytes
/
settings.js
File metadata and controls
25 lines (19 loc) · 783 Bytes
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
// settings.js — tabsentry
const $ = id => document.getElementById(id);
// load current values
async function loadSettings() {
const { settings = {} } = await chrome.storage.local.get("settings");
$("threshold").value = settings.threshold ?? 5;
$("idle-timeout").value = settings.idleTimeout ?? 10;
}
loadSettings();
// save on click
$("save-settings").addEventListener("click", async () => {
const threshold = parseInt($("threshold").value, 10);
const idleTimeout = parseInt($("idle-timeout").value, 10);
await chrome.storage.local.set({ settings: { threshold, idleTimeout } });
$("status").textContent = "Saved!";
setTimeout(() => ($("status").textContent = ""), 2000);
// ping bg to re-read
chrome.runtime.sendMessage({ type: "refreshSettings" });
});