2022-02-23 22:17:12 +01:00
|
|
|
var newDateObj = new Date();
|
|
|
|
newDateObj = new Date(newDateObj.getTime() + 1000*20)
|
|
|
|
|
2022-02-23 21:55:13 +01:00
|
|
|
function handleUpdate() {
|
2022-02-23 22:17:12 +01:00
|
|
|
resp = httpGet("/api/v1/data?markRead=mark");
|
2022-02-23 21:55:13 +01:00
|
|
|
|
|
|
|
var data = JSON.parse(resp);
|
2022-02-23 22:17:12 +01:00
|
|
|
if(data.changed){
|
|
|
|
newDateObj = data.countdownGoal;
|
|
|
|
}
|
|
|
|
|
2022-02-23 21:55:13 +01:00
|
|
|
if (data.mode == "clock") {
|
|
|
|
document.getElementById("timer").innerHTML = getTime();
|
|
|
|
document.getElementById("testImg").style.display = "none";
|
|
|
|
|
|
|
|
} else if (data.mode == "timer") {
|
2022-02-23 22:17:12 +01:00
|
|
|
|
|
|
|
countdown(
|
|
|
|
newDateObj,
|
|
|
|
function(ts) {
|
|
|
|
// console.log(ts)
|
|
|
|
if(ts.value <= 0){
|
|
|
|
document.getElementById("timer").innerHTML = ('00'+ts.hours).slice(-2) + ":" + ('00'+ts.minutes).slice(-2) + ":" + ('00'+ts.seconds).slice(-2);
|
|
|
|
}else{
|
|
|
|
document.getElementById("timer").innerHTML = "00:00:00"
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
countdown.HOURS|countdown.MINUTES|countdown.SECONDS);
|
2022-02-23 21:55:13 +01:00
|
|
|
document.getElementById("testImg").style.display = "none";
|
|
|
|
|
|
|
|
} else if (data.mode == "black") {
|
|
|
|
document.getElementById("timer").innerHTML = "";
|
|
|
|
document.getElementById("testImg").style.display = "none";
|
|
|
|
|
|
|
|
} else if (data.mode == "test") {
|
|
|
|
document.getElementById("timer").innerHTML = "";
|
|
|
|
document.getElementById("testImg").style.display = "block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function httpGet(theUrl) {
|
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
|
|
xmlHttp.open("GET", theUrl, false); // false for synchronous request
|
|
|
|
xmlHttp.send(null);
|
|
|
|
return xmlHttp.responseText;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTime() {
|
|
|
|
var date = new Date();
|
|
|
|
var h = date.getHours(); // 0 - 23
|
|
|
|
var m = date.getMinutes(); // 0 - 59
|
|
|
|
var s = date.getSeconds(); // 0 - 59
|
|
|
|
|
|
|
|
h = h < 10 ? "0" + h : h;
|
|
|
|
m = m < 10 ? "0" + m : m;
|
|
|
|
s = s < 10 ? "0" + s : s;
|
|
|
|
|
|
|
|
var time = h + ":" + m + ":" + s;
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(handleUpdate, 50);
|