blob: a0b6b719ea374770329a96ebdc5aec335169d6c5 (
plain) (
blame)
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
|
function saveOptions() {
let timefmt;
if (document.getElementById('t24').checked)
timefmt = 24;
else if (document.getElementById('t12').checked)
timefmt = 12;
localStorage['timefmt'] = timefmt;
localStorage['fg'] = document.getElementById('fg').value;
localStorage['fg_date'] = document.getElementById('fg_date').value;
localStorage['bg'] = document.getElementById('bg').value;
let status = document.getElementById('status');
status.textContent = 'Options saved';
setTimeout(function() { status.textContent = '' }, 2000);
}
function restoreOptions() {
// default to 24 for both unset and invalid
let timefmt = localStorage['timefmt'] || 24;
let timefmt_btn = document.getElementById('t' + timefmt) ||
document.getElementById('t24');
timefmt_btn.checked = true;
let fg = localStorage['fg'];
if (fg)
document.getElementById('fg').value = fg;
let fg_date = localStorage['fg_date'];
if (fg_date)
document.getElementById('fg_date').value = fg_date;
let bg = localStorage['bg'];
if (bg)
document.getElementById('bg').value = bg;
}
function startOptions() {
restoreOptions();
document.getElementById('save').addEventListener('click', saveOptions);
}
window.onload = startOptions;
|