summaryrefslogtreecommitdiff
path: root/tempo.js
blob: 738b2f44abc0b241c868947e4ab8f8288421d93b (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
// 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.

var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

function padTime(x) {
	if(x < 10) {
		return '0' + x;
	} else {
		return x;
	}
}

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

	var date = new Date();

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

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

	var str_d = dd + ' ' + months[dm] + ' ' + dy;

	if(timeformat == '12') {
		h = (h + 11) % 12 + 1;
	}

	document.getElementById('h').innerHTML = padTime(h);
	document.getElementById('m').innerHTML = padTime(m);
	document.getElementById('s').innerHTML = padTime(s);
	document.getElementById('dateval').innerHTML = str_d;
}

function startTempo() {
	updateTime();

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

window.onload = startTempo;

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