-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathoptions.js
35 lines (30 loc) · 1.15 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
//
// (c) Lauritz Holtmann
//
const WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000;
const saveOptions = () => {
const cacheDuration = document.getElementById('cache-duration').value;
const ignoredDomains = document.getElementById('ignored-domains').value.split('\n').map(domain => domain.trim()).filter(domain => domain);
chrome.storage.sync.set(
{ cacheDuration, ignoredDomains },
() => {
// Update status to let user know options were saved.
const status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(() => {
status.textContent = '';
}, 750);
}
);
};
const restoreOptions = () => {
chrome.storage.sync.get(
{ cacheDuration: WEEK_IN_MS, ignoredDomains: [] },
(items) => {
document.getElementById('cache-duration').value = items.cacheDuration;
document.getElementById('ignored-domains').value = items.ignoredDomains.join('\n');
}
);
};
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);