summaryrefslogtreecommitdiff
path: root/options.js
blob: 045b2b3c08a5433c9bf6afeac3713c0d4e31a0f4 (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
// Copyright 2014 David Vazgenovich Shakaryan <dvshakaryan@gmail.com>
// Distributed under the terms of the GNU General Public License v2.
// See http://www.gnu.org/licenses/gpl-2.0.txt for the full license text.

function save_options() {
	var select = document.getElementById('timeformat');
	var timeformat = select.children[select.selectedIndex].value;
	localStorage['timeformat'] = timeformat;

	var status = document.getElementById('status');
	status.innerHTML = 'Options saved.';

	setTimeout(function() {status.innerHTML = '&nbsp;'}, 1000);
}

function restore_options() {
	var timeformat = localStorage['timeformat'];

	if(!timeformat) {
		timeformat = '24';
	}

	var select = document.getElementById('timeformat');

	for(var i = 0; i < select.children.length; i++) {
		var child = select.children[i];

		if(child.value == timeformat) {
			child.selected = 'true';

			break;
		}
	}
}

function start_options() {
	restore_options();

	document.querySelector('#save').addEventListener('click', save_options);
}

window.onload = start_options;