forked from yemble/chrome-strava-filter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
64 lines (56 loc) · 2.09 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
// 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 hideShortCycle = document.getElementById('hide_short_cycle').selectedOptions[0].value;
var hideShortWalk = document.getElementById('hide_short_walk').selectedOptions[0].value;
chrome.storage.sync.set({
action: action,
hideCommute: hideCommute,
hideVirtual: hideVirtual,
hideChallenge: hideChallenge,
hideShortCycle: hideShortCycle,
hideShortWalk: hideShortWalk,
}, 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,
hideShortCycle: 0,
hideShortWalk: 0,
}, 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;
var csSel = document.getElementById('hide_short_cycle');
var cwSel = document.getElementById('hide_short_walk');
setSelected(csSel, items.hideShortCycle)
setSelected(cwSel, items.hideShortWalk)
});
}
// 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);