Skip to content

Commit

Permalink
separate update of data from clock function and update clock every se…
Browse files Browse the repository at this point in the history
…cond
  • Loading branch information
burnoutberni committed Dec 14, 2016
1 parent 96b8ae0 commit 2ea7eb8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions site/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ function update()
document.getElementById("error").style.display = "none";
document.getElementById("container").style.opacity = "1";

var currentTime = new Date();
document.getElementById('currentTime').innerHTML = (currentTime.getHours() < 10 ? '0' : '') + currentTime.getHours() + ":" + (currentTime.getMinutes() < 10 ? '0' : '') + currentTime.getMinutes();
var req = new XMLHttpRequest();
req.open('GET', api_url);
req.onreadystatechange = function () {
Expand Down Expand Up @@ -256,7 +254,17 @@ function update()
req.send();
}

function clock() {
var currentTime = new Date();
document.getElementById('currentTime').innerHTML =
(currentTime.getHours() < 10 ? '0' : '') + currentTime.getHours() + ":"
+ (currentTime.getMinutes() < 10 ? '0' : '') + currentTime.getMinutes() + ":"
+ (currentTime.getSeconds() < 10 ? '0' : '') + currentTime.getSeconds();
}

window.onload = function () {
clock();
update();
window.setInterval(clock, 1000);
window.setInterval(update, 10000);
};

0 comments on commit 2ea7eb8

Please sign in to comment.