summaryrefslogtreecommitdiff
path: root/boring.js
blob: cd26733ae511b05ad56dad8841078e73f9541f6f (plain)
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
50
Function.prototype.Timer = function (interval, calls, onend) {
	var count = 0;
	var payloadFunction = this;
	var startTime = new Date();
	var callbackFunction = function () {
		return payloadFunction(startTime, count);
	};
	var endFunction = function () {
		if (onend) {
			onend(startTime, count, calls);
		}
	};
	var timerFunction =  function () {
		count++;
		if (count < calls && callbackFunction() != false) {
			window.setTimeout(timerFunction, interval);
		} else {
			endFunction();
		}
	};
	timerFunction();
 };

function leadingzero (number) {
	return (number < 10) ? '0' + number : number;
}

function countdown (seconds, target) {
	var element = document.getElementById(target);

	var showTimer = function () {
		if (seconds > 0) {
			var m = Math.floor((seconds % 3600) / 60);
			var s = seconds % 60;
			element.innerHTML=
			leadingzero(m) + ':' +
			leadingzero(s);
			seconds--;
		} else {
			return false;
		}
	};
	
	var completed = function () {
		printPlayer();
	};

	showTimer.Timer(1000, Infinity, completed);
}