summaryrefslogtreecommitdiff
path: root/tempo.js
blob: ae3fa22226b14f28318dfb761c72941d5760fb47 (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
45
46
47
48
49
let timefmt = null;
const months = ['January', 'February', 'March', 'April', 'May', 'June',
	'July', 'August', 'September', 'October', 'November', 'December'];

function padTime(x) {
	return (x < 10) ? '0' + x : x;
}

function updateTime() {
	let date = new Date();

	let h = date.getHours();
	let m = date.getMinutes();
	let s = date.getSeconds();

	let dd = date.getDate();
	let dm = date.getMonth();
	let dy = date.getFullYear();

	if (timefmt == 12) // default to 24
		h = (h + 11) % 12 + 1;

	let str_t = padTime(h) + '&nbsp;&nbsp;' + padTime(m) +
		'&nbsp;&nbsp' + padTime(s);
	let str_d = dd + ' ' + months[dm] + ' ' + dy;

	document.getElementById('timeval').innerHTML = str_t;
	document.getElementById('dateval').innerHTML = str_d;
}

function startTempo() {
	timefmt = localStorage['timefmt'];

	let fg = localStorage['fg'];
	if (fg)
		document.body.style.color = fg;

	let bg = localStorage['bg'];
	if (bg)
		document.body.style.backgroundColor = bg;

	updateTime();
	setTimeout(function() { updateTime(); setInterval(updateTime, 1000) },
		1000 - (new Date()).getTime() % 1000);
}

window.onload = startTempo;

document.addEventListener('contextmenu', function(e) { e.preventDefault() });