2022-02-23 22:17:12 +01:00
|
|
|
var newDateObj = new Date();
|
|
|
|
newDateObj = new Date(newDateObj.getTime() + 1000*20)
|
|
|
|
|
2022-02-24 21:08:31 +01:00
|
|
|
allowFullscreen = true
|
|
|
|
|
2022-02-24 19:11:13 +01:00
|
|
|
function enterFullscreen(element) {
|
|
|
|
if(element.requestFullscreen) {
|
|
|
|
element.requestFullscreen();
|
|
|
|
} else if(element.msRequestFullscreen) { // for IE11 (remove June 15, 2022)
|
|
|
|
element.msRequestFullscreen();
|
|
|
|
} else if(element.webkitRequestFullscreen) { // iOS Safari
|
|
|
|
element.webkitRequestFullscreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 22:18:21 +01:00
|
|
|
function percentage(partialValue, totalValue) {
|
|
|
|
return (100 * partialValue) / totalValue;
|
|
|
|
}
|
|
|
|
|
2022-02-24 19:11:13 +01:00
|
|
|
function updateFullscreen(){
|
2022-02-24 21:08:31 +01:00
|
|
|
if(JSON.parse(document.getElementById("incomeData").innerHTML).defaultFullScreen && allowFullscreen){
|
2022-02-24 19:11:13 +01:00
|
|
|
enterFullscreen(document.documentElement)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function msToTime(s, data) {
|
|
|
|
isSmallerThenZero = false
|
|
|
|
if(s < 0){
|
|
|
|
isSmallerThenZero = true
|
|
|
|
}
|
|
|
|
|
|
|
|
var ms = s % 1000;
|
|
|
|
s = (s - ms) / 1000;
|
|
|
|
var secs = s % 60;
|
|
|
|
s = (s - secs) / 60;
|
|
|
|
var mins = s % 60;
|
|
|
|
var hrs = (s - mins) / 60;
|
|
|
|
let out = ""
|
|
|
|
|
|
|
|
if(!data.showMilliSeconds){
|
|
|
|
out = ('00' + Math.abs(hrs)).slice(-2) + ':' + ('00'+Math.abs(mins)).slice(-2) + ':' + ('00'+Math.abs(secs)).slice(-2)
|
|
|
|
}else {
|
|
|
|
out = ('00' + Math.abs(hrs)).slice(-2) + ':' + ('00'+Math.abs(mins)).slice(-2) + ':' + ('00'+Math.abs(secs)).slice(-2) + '.' + ('000'+Math.abs(ms)).slice(-3)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isSmallerThenZero){
|
|
|
|
out = "-" + out
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2022-02-24 22:18:21 +01:00
|
|
|
function findProgessColor(colors, value){
|
|
|
|
console.info("\n\n\n\n\n")
|
|
|
|
const allColors = Object.keys(colors);
|
|
|
|
let resColor = colors["START"]
|
|
|
|
|
|
|
|
for(let color in allColors){
|
|
|
|
const currColor = allColors[color]
|
|
|
|
console.log(color, currColor, parseInt(currColor), value, colors[String(currColor)])
|
|
|
|
if(value <= parseInt(currColor)){
|
|
|
|
console.log("trith")
|
|
|
|
resColor = colors[currColor]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.info(resColor, value)
|
|
|
|
return(resColor)
|
|
|
|
}
|
|
|
|
|
2022-02-23 21:55:13 +01:00
|
|
|
function handleUpdate() {
|
2022-02-24 21:08:31 +01:00
|
|
|
resp = httpGet("/api/v1/data");
|
2022-02-23 21:55:13 +01:00
|
|
|
|
|
|
|
var data = JSON.parse(resp);
|
2022-02-24 19:11:13 +01:00
|
|
|
document.getElementById("incomeData").innerHTML = JSON.stringify(data)
|
|
|
|
|
2022-02-24 21:08:31 +01:00
|
|
|
if(data.defaultFullScreen && document.getElementById("initalDate").innerHTML.includes("true") && allowFullscreen){
|
2022-02-24 19:11:13 +01:00
|
|
|
enterFullscreen(document.documentElement);
|
|
|
|
document.getElementById("initalDate").innerHTML = "false"
|
2022-02-23 22:17:12 +01:00
|
|
|
}
|
|
|
|
|
2022-02-24 21:08:31 +01:00
|
|
|
if(data.showMessage) {
|
|
|
|
document.getElementById("overlay").style.display = "block";
|
|
|
|
document.getElementById("text").innerHTML = data.message
|
|
|
|
}else{
|
|
|
|
off()
|
|
|
|
}
|
|
|
|
|
|
|
|
if(new Date().getTime() - data.messageAppearTime < 5000) {
|
|
|
|
if (! document.getElementById("text").classList.contains('blink') ){
|
|
|
|
document.getElementById("text").classList.add("blink")
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if ( document.getElementById("text").classList.contains('blink') ){
|
|
|
|
document.getElementById("text").classList.remove("blink")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 19:11:13 +01:00
|
|
|
|
2022-02-23 21:55:13 +01:00
|
|
|
if (data.mode == "clock") {
|
|
|
|
document.getElementById("timer").innerHTML = getTime();
|
|
|
|
document.getElementById("testImg").style.display = "none";
|
2022-02-24 22:18:21 +01:00
|
|
|
document.getElementById("wholeProgBar").style.display = "none";
|
2022-02-23 21:55:13 +01:00
|
|
|
|
|
|
|
} else if (data.mode == "timer") {
|
2022-02-24 22:18:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("wholeProgBar").style.display = "block";
|
2022-02-24 20:17:24 +01:00
|
|
|
if(data.timerRunState){
|
|
|
|
const now = new Date()
|
|
|
|
const diff = data.countdownGoal - now.getTime()
|
|
|
|
document.getElementById("timer").innerHTML = msToTime(diff, data);
|
2022-02-24 22:18:21 +01:00
|
|
|
document.getElementById("progBar").style.width = percentage(diff, data.timeAmountInital) + "%";
|
|
|
|
document.getElementById("progBar").style.backgroundColor = findProgessColor(data.colorSegments,diff)
|
2022-02-24 20:17:24 +01:00
|
|
|
document.getElementById("testImg").style.display = "none";
|
2022-02-24 22:18:21 +01:00
|
|
|
|
2022-02-24 20:17:24 +01:00
|
|
|
}
|
2022-02-24 21:08:31 +01:00
|
|
|
if(data.showTimeOnCountdown){
|
|
|
|
document.getElementById("clockSec").innerHTML = getTime();
|
|
|
|
} else {
|
|
|
|
document.getElementById("clockSec").innerHTML = "";
|
|
|
|
}
|
2022-02-23 21:55:13 +01:00
|
|
|
|
|
|
|
} else if (data.mode == "black") {
|
|
|
|
document.getElementById("timer").innerHTML = "";
|
|
|
|
document.getElementById("testImg").style.display = "none";
|
2022-02-24 22:18:21 +01:00
|
|
|
document.getElementById("wholeProgBar").style.display = "none";
|
2022-02-23 21:55:13 +01:00
|
|
|
|
|
|
|
} else if (data.mode == "test") {
|
|
|
|
document.getElementById("timer").innerHTML = "";
|
|
|
|
document.getElementById("testImg").style.display = "block";
|
2022-02-24 22:18:21 +01:00
|
|
|
document.getElementById("progBar").style.display = "none";
|
2022-02-23 21:55:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-24 21:08:31 +01:00
|
|
|
function on() {
|
|
|
|
document.getElementById("overlay").style.display = "block";
|
|
|
|
}
|
|
|
|
|
|
|
|
function off() {
|
|
|
|
document.getElementById("overlay").style.display = "none";
|
|
|
|
}
|
|
|
|
|
2022-02-24 19:11:13 +01:00
|
|
|
setInterval(handleUpdate, 200);
|
|
|
|
|
|
|
|
let temp = new URLSearchParams(window.location.search).get("smaller");
|
|
|
|
|
|
|
|
|
|
|
|
if (temp == "true") {
|
|
|
|
var cssURL = '/css/smallerTextMod.css';
|
|
|
|
document.head.innerHTML +='<link rel="stylesheet" href="' + cssURL + '"/>'
|
2022-02-24 21:08:31 +01:00
|
|
|
allowFullscreen = false
|
2022-02-24 19:11:13 +01:00
|
|
|
}
|