-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathoptions.js
51 lines (45 loc) · 1.68 KB
/
options.js
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
51
/* eslint-disable functional/no-conditional-statement */
/* eslint-disable functional/no-expression-statement */
/** @typedef {{tabPosition: string | undefined}} Settings */
/**
* @param {Event} e
*/
function saveOptions(e) {
const checkedTabPositionInput = document.querySelector(
"input[name='tab-position']:checked"
);
const tabPosition =
checkedTabPositionInput instanceof HTMLInputElement
? checkedTabPositionInput.value
: undefined;
/** @type {Settings} */
const settings = { tabPosition: tabPosition };
// eslint-disable-next-line @typescript-eslint/no-floating-promises
chrome.storage.sync.set(settings);
e.preventDefault();
}
// eslint-disable-next-line functional/functional-parameters
function restoreOptions() {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
chrome.storage.sync.get((/** @type {Settings} */ settings) => {
const backgroundInput = document.querySelector(
"input[name='tab-position'][value='background']"
);
if (backgroundInput instanceof HTMLInputElement) {
// eslint-disable-next-line functional/immutable-data
backgroundInput.checked = settings.tabPosition === "background";
}
const foregroundInput = document.querySelector(
"input[name='tab-position'][value='foreground']"
);
if (foregroundInput instanceof HTMLInputElement) {
// eslint-disable-next-line functional/immutable-data
foregroundInput.checked = settings.tabPosition === "foreground";
}
});
}
document.addEventListener("DOMContentLoaded", restoreOptions);
const form = document.querySelector("form");
if (form instanceof HTMLFormElement) {
form.addEventListener("submit", saveOptions);
}