You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wubloader/thrimbletrimmer/clock.html

57 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Stream Time</title>
<style type="text/css">
#clock {
margin-bottom: 3px;
}
</style>
</head>
<body>
<div id="clock"></div>
<div><input type="number" id="delay" value="10" min="0" /> seconds of delay</div>
<script type="text/javascript">
let busStartTime = null;
function updateClock() {
let delay = parseInt(document.getElementById("delay").value);
if (isNaN(delay)) {
delay = 0;
}
let time = (new Date() - busStartTime) / 1000 - delay;
let sign = "";
if (time < 0) {
time = -time;
sign = "-";
}
let hours = Math.trunc(time / 3600).toString();
let mins = Math.trunc((time % 3600) / 60).toString();
let secs = Math.trunc(time % 60).toString();
if (mins.length < 2) {
mins = "0" + mins;
}
if (secs.length < 2) {
secs = "0" + secs;
}
let formatted = sign + hours + ":" + mins + ":" + secs;
document.getElementById("clock").innerText = formatted;
}
async function initialize() {
const dataResponse = await fetch("/thrimshim/defaults");
const data = await dataResponse.json();
busStartTime = new Date(data.bustime_start);
setInterval(updateClock, 1000);
}
initialize();
</script>
</body>
</html>