summaryrefslogtreecommitdiff
path: root/options.js
blob: a21852878d9045c113147eb80a977e3bb70aac15 (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
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 val = localStorage['timefmt'] || 24;
	let btn = document.getElementById('t' + val) ||
		document.getElementById('t24');
	btn.checked = true;

	if ((val = localStorage['fg']))
		document.getElementById('fg').value = val;
	if ((val = localStorage['fg_date']))
		document.getElementById('fg_date').value = val;
	if ((val = localStorage['bg']))
		document.getElementById('bg').value = val;
}

function startOptions() {
	restoreOptions();

	document.getElementById('save').addEventListener('click', saveOptions);
}

window.onload = startOptions;