-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
48 lines (43 loc) · 1.61 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
// Saves options to chrome.storage
const saveOptions = () => {
const ci_keywords = document.getElementById('ci-keywords').value;
console.log(ci_keywords);
const cs_keywords = document.getElementById('cs-keywords').value;
const ci_domains = document.getElementById('domains').value;
chrome.storage.sync.set({
ciKeywords: JSON.parse(ci_keywords),
csKeywords: JSON.parse(cs_keywords),
domains: JSON.parse(ci_domains)
},
() => {
// Update status to let user know options were saved.
const status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(() => {
status.textContent = '';
}, 1000);
// reload page
chrome.tabs.query({"url": "https://news.ycombinator.com/*"}, function(tabs) {
tabs.forEach(tab => { chrome.tabs.reload(tab.id) });
})
}
);
};
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
const restoreOptions = () => {
chrome.storage.sync.get(
{ ciKeywords: [], csKeywords: [], domains: [] },
(items) => {
console.log(items);
CI_KEYWORDS = items.ciKeywords;
CS_KEYWORDS = items.csKeywords;
DOMAINS = items.domains;
document.getElementById('ci-keywords').value = JSON.stringify(items.ciKeywords);
document.getElementById('cs-keywords').value = JSON.stringify(items.csKeywords);
document.getElementById('domains').value = JSON.stringify(items.domains);
}
);
};
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);