This repository has been archived by the owner on Sep 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
66 lines (58 loc) · 2.19 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Saves options to chrome.storage
function save_options() {
var action = document.getElementById('action').value;
var hideCommute = document.getElementById('hide_commute').checked;
var hideVirtual = document.getElementById('hide_virtual').checked;
var hideChallenge = document.getElementById('hide_challenge').checked;
var showPhoto = document.getElementById('showPhoto').checked;
var showLongCycle = document.getElementById('showLongCycle').selectedOptions[0].value;
var autoPage = document.getElementById('autoPage').selectedOptions[0].value;
chrome.storage.sync.set({
action: action,
hideCommute: hideCommute,
hideVirtual: hideVirtual,
hideChallenge: hideChallenge,
showPhoto: showPhoto,
showLongCycle: parseInt(showLongCycle),
autoPage: parseInt(autoPage),
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Saved.';
setTimeout(function() {
status.textContent = '';
}, 1000);
});
}
// Restores select box and checkbox state using the preferences stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get({
action: 'fade',
hideCommute: true,
hideVirtual: true,
hideChallenge: false,
showPhoto: true,
showLongCycle: 0,
autoPage: 3,
}, function(items) {
document.getElementById('action').value = items.action;
document.getElementById('hide_commute').checked = items.hideCommute;
document.getElementById('hide_virtual').checked = items.hideVirtual;
document.getElementById('hide_challenge').checked = items.hideChallenge;
document.getElementById('showPhoto').checked = items.showPhoto;
setSelected(document.getElementById('showLongCycle'), items.showLongCycle)
setSelected(document.getElementById('autoPage'), items.autoPage)
});
}
// set value for a select element
function setSelected(sel, val) {
var opts = sel.options;
for(var i = 0; i < opts.length; i++) {
if(opts[i].value == val) {
sel.selectedIndex = i;
return;
}
}
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);