diff options
Diffstat (limited to 'tempo.js')
-rw-r--r-- | tempo.js | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -29,6 +29,14 @@ function updateTime() { dd + ' ' + MONTHS[dm] + ' ' + dy; } +// recursively calling setTimeout instead of using setInterval allows us to +// correct for any drift caused by imprecise delays. +function updateTimeRecursive() { + updateTime(); + // +1ms to avoid updating too early + setTimeout(updateTimeRecursive, 1001 - new Date().getTime() % 1000); +} + function startTempo() { timefmt = localStorage['timefmt']; @@ -40,11 +48,9 @@ function startTempo() { if ((val = localStorage['bg'])) document.body.style.backgroundColor = val; - updateTime(); - setTimeout(function() { updateTime(); setInterval(updateTime, 1000) }, - 1000 - (new Date()).getTime() % 1000); + updateTimeRecursive(); } window.onload = startTempo; -document.addEventListener('contextmenu', function(e) { e.preventDefault() }); +document.addEventListener('contextmenu', e => e.preventDefault()); |