-
Notifications
You must be signed in to change notification settings - Fork 14
/
shared.js
40 lines (34 loc) · 959 Bytes
/
shared.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
// Local storage key
const STORAGE_KEY = 'dormancy.configuration';
// Default values for options
const defaults = {
timeout: 10,
activeWindow: false,
excludedWebsites: []
};
let defaultConfig = {
timeout: {
label: browser.i18n.getMessage('optionTimeout'),
value: defaults.timeout
},
activeWindow: {
label: browser.i18n.getMessage('optionActiveWindow'),
value: defaults.activeWindow
},
excludedWebsites: {
label: browser.i18n.getMessage('optionExcludedWebsites'),
value: defaults.excludedWebsites
}
};
// Returns json obj - either user config or default config
async function loadConfig() {
let data = await browser.storage.local.get(STORAGE_KEY);
let config = { ...defaultConfig, ...data[STORAGE_KEY] };
return config;
}
// Save data to local storage
async function saveConfig(data) {
let saveData = {};
saveData[STORAGE_KEY] = data;
browser.storage.local.set(saveData).then(null, console.error);
}