-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathoptions.js
More file actions
55 lines (54 loc) · 1.84 KB
/
options.js
File metadata and controls
55 lines (54 loc) · 1.84 KB
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
52
53
54
55
/*eslint-disable no-undef */
function reset(){
window.open("https://www.vocabulary.com/lists/notalist/bee?clearData=1");
}
function statusUpdater(txt){
const status = document.getElementById('status');
status.textContent = txt;
setTimeout(function() {
status.textContent = '';
}, 1500);
}
//saves options to chrome.storage
function saveOptions() {
const query = document.getElementById('query').value||"test";
const hide = document.getElementById('hide').checked||false;
const strike = parseInt(document.getElementById('strike').value,10)||5;
if(strike > 100 || strike < 3) return statusUpdater('Invalid Options : Strike must be between 3 and 100')
chrome.storage.sync.set({
query,
strike,
hide
}, statusUpdater.bind(this, 'Options Saved'));
}
/*
* restores select box and checkbox state using the preferences
* stored in chrome.storage.
*/
function restoreOptions() {
chrome.storage.sync.get({
"query": "test",
"strike": 5,
"hide": false
}, function(items) {
document.getElementById('query').value= items.query;
document.getElementById('hide').checked= items.hide;
document.getElementById('strike').value= items.strike;
document.getElementById('status').textContent="";
});
}
//start up : add listeners
document.addEventListener('DOMContentLoaded', restoreOptions);
Array.from(document.querySelectorAll("input")).map(x=>x.addEventListener("input",function(){
document.getElementById('status').innerHTML="<span style='font-weight:600px;color:red'>UNSAVED</span>"
}))
document.getElementById('save').addEventListener(
'click',
saveOptions
);
document.getElementById('abandon').addEventListener(
'click',
restoreOptions
);
restoreOptions();
document.getElementById('reset').addEventListener('click', reset)