mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-11 23:45:56 +00:00
Added element check, formatting
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
//The content of this file get set into htmlHeadStyle (new_http.cs)
|
||||
|
||||
var firstTime,
|
||||
lastTime,
|
||||
req = null;
|
||||
lastTime,
|
||||
req = null;
|
||||
var onlineFor;
|
||||
var onlineForEl = null;
|
||||
|
||||
@ -10,73 +10,79 @@ var getElement = (id) => document.getElementById(id);
|
||||
|
||||
// refresh status section every 3 seconds
|
||||
function showState() {
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
if (req != null) {
|
||||
req.abort();
|
||||
}
|
||||
req = new XMLHttpRequest();
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
if (
|
||||
!(
|
||||
document.activeElement.tagName == "INPUT" &&
|
||||
(document.activeElement.type == "number" || document.activeElement.type == "color")
|
||||
)
|
||||
) {
|
||||
getElement("state").innerHTML = req.responseText;
|
||||
}
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
lastTime = setTimeout(showState, 3e3);
|
||||
}
|
||||
};
|
||||
req.open("GET", "index?state=1", true);
|
||||
req.send();
|
||||
firstTime = setTimeout(showState, 3e3);
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
if (req != null) {
|
||||
req.abort();
|
||||
}
|
||||
req = new XMLHttpRequest();
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
if (
|
||||
!(
|
||||
document.activeElement.tagName == "INPUT" &&
|
||||
(document.activeElement.type == "number" || document.activeElement.type == "color")
|
||||
)
|
||||
) {
|
||||
var stateEl = getElement("state");
|
||||
if (stateEl) {
|
||||
stateEl.innerHTML = req.responseText;
|
||||
}
|
||||
}
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
lastTime = setTimeout(showState, 3e3);
|
||||
}
|
||||
};
|
||||
req.open("GET", "index?state=1", true);
|
||||
req.send();
|
||||
firstTime = setTimeout(showState, 3e3);
|
||||
}
|
||||
|
||||
function fmtUpTime(totalSeconds) {
|
||||
var days, hours, minutes, seconds;
|
||||
var days, hours, minutes, seconds;
|
||||
|
||||
days = Math.floor(totalSeconds / (24 * 60 * 60));
|
||||
totalSeconds = totalSeconds % (24 * 60 * 60);
|
||||
hours = Math.floor(totalSeconds / (60 * 60));
|
||||
totalSeconds = totalSeconds % (60 * 60);
|
||||
minutes = Math.floor(totalSeconds / 60);
|
||||
seconds = totalSeconds % 60;
|
||||
days = Math.floor(totalSeconds / (24 * 60 * 60));
|
||||
totalSeconds = totalSeconds % (24 * 60 * 60);
|
||||
hours = Math.floor(totalSeconds / (60 * 60));
|
||||
totalSeconds = totalSeconds % (60 * 60);
|
||||
minutes = Math.floor(totalSeconds / 60);
|
||||
seconds = totalSeconds % 60;
|
||||
|
||||
if (days > 0) {
|
||||
return `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (minutes > 0) {
|
||||
return `${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
return `just ${seconds} seconds`;
|
||||
if (days > 0) {
|
||||
return `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (minutes > 0) {
|
||||
return `${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
return `just ${seconds} seconds`;
|
||||
}
|
||||
|
||||
function updateOnlineFor() {
|
||||
onlineForEl.textContent = fmtUpTime(++onlineFor);
|
||||
onlineForEl.textContent = fmtUpTime(++onlineFor);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
onlineForEl = getElement("onlineFor");
|
||||
if (onlineForEl) {
|
||||
onlineFor = parseInt(onlineForEl.dataset.initial, 10); //We have some valid value
|
||||
if (onlineFor) {
|
||||
setInterval(updateOnlineFor, 1000);
|
||||
}
|
||||
}
|
||||
onlineForEl = getElement("onlineFor");
|
||||
if (onlineForEl) {
|
||||
onlineFor = parseInt(onlineForEl.dataset.initial, 10); //We have some valid value
|
||||
if (onlineFor) {
|
||||
setInterval(updateOnlineFor, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
showState();
|
||||
showState();
|
||||
}
|
||||
|
||||
window.addEventListener("load", onLoad);
|
||||
history.pushState(null, "", "index"); // drop actions like 'toggle' from URL
|
||||
|
||||
setTimeout(() => {
|
||||
getElement("changed").innerHTML = "";
|
||||
var changedEl = getElement("changed");
|
||||
if (changedEl) {
|
||||
changedEl.innerHTML = "";
|
||||
}
|
||||
}, 5e3); // hide change info
|
||||
|
||||
Reference in New Issue
Block a user