diff options
Diffstat (limited to 'boring.js')
| -rw-r--r-- | boring.js | 50 |
1 files changed, 50 insertions, 0 deletions
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); +} + |
