summaryrefslogtreecommitdiff
path: root/options.js
blob: c3f008bf63df2e1298ef22bb4a5eb8583ebe68fe (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
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['bg'] = document.getElementById('bg').value;

	let status = document.getElementById('status');
	status.innerHTML = 'Options saved';
	setTimeout(function() { status.innerHTML = '' }, 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 bg = localStorage['bg'];
	if (bg)
		document.getElementById('bg').value = bg;
}

function startOptions() {
	restoreOptions();

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

window.onload = startOptions;