From c5639ee890215e4e8e0f544821ea8d285ca58eb8 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 13 Sep 2014 22:26:58 +0200 Subject: init --- boring.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 boring.js (limited to 'boring.js') diff --git a/boring.js b/boring.js new file mode 100644 index 0000000..cd26733 --- /dev/null +++ b/boring.js @@ -0,0 +1,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); +} + -- cgit v1.2.3