-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.js
More file actions
33 lines (28 loc) · 987 Bytes
/
settings.js
File metadata and controls
33 lines (28 loc) · 987 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
26
27
28
29
30
31
32
33
const DEFAULT_PORT = 23119;
const portInput = document.getElementById("portInput");
const saveBtn = document.getElementById("saveBtn");
const cancelBtn = document.getElementById("cancelBtn");
const msg = document.getElementById("msg");
function loadSettings() {
browser.storage.local.get({ jabrefPort: DEFAULT_PORT }).then((res) => {
portInput.value = res.jabrefPort;
}).catch((e) => {
console.warn('Failed to load settings', e);
});
}
function saveSettings() {
const port = parseInt(portInput.value, 10) || DEFAULT_PORT;
browser.storage.local.set({ jabrefPort: port }).then(() => {
msg.textContent = "Saved.";
setTimeout(() => (msg.textContent = ""), 1500);
}).catch((e) => {
console.warn('Failed to save settings', e);
msg.textContent = "Save failed.";
setTimeout(() => (msg.textContent = ""), 1500);
});
}
saveBtn.addEventListener("click", saveSettings);
cancelBtn.addEventListener("click", () => {
window.close();
});
loadSettings();