-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
common.js
50 lines (45 loc) · 1.2 KB
/
common.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
// Polyfill for Chrome
// https://bugs.chromium.org/p/chromium/issues/detail?id=798169
if (typeof globalThis.browser === "undefined") {
globalThis.browser = globalThis.chrome;
}
/**
* @typedef {{
* syncSettings: boolean,
* thumbnailMode: 'hidden' | 'hidden-except-hover' | 'blurred' | 'solid-color' | 'normal',
* disabledOnPages: {
* results: boolean,
* channel: boolean,
* playlist: boolean,
* watch: boolean,
* subscriptions: boolean,
* everywhere: boolean,
* },
* }} Options
*/
/** @type {Options} */
const defaultOptions = {
syncSettings: true,
disabledOnPages: {
results: false,
channel: false,
playlist: false,
watch: false,
subscriptions: false,
everywhere: false,
},
thumbnailMode: 'hidden',
}
/**
* @returns {Promise<Options>}
*/
const loadOptions = async () => {
/** @type {boolean} */
const syncSettings = (await new Promise((resolve) => {
browser.storage.local.get(defaultOptions, resolve);
})).syncSettings ?? defaultOptions.syncSettings;
const options = await new Promise((resolve) => {
browser.storage[syncSettings ? 'sync' : 'local'].get(defaultOptions, resolve);
})
return { ...defaultOptions, ...options }
}