-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval-timer.html
More file actions
92 lines (84 loc) · 3.35 KB
/
interval-timer.html
File metadata and controls
92 lines (84 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<style type="text/css">
html, body {
margin: 0;
padding: 0;
background-color: black;
color: white;
display: flex;
height: 100%;
width: 100%;
font-family: Helvetica, Arial, sans-serif;
font-size: 3vw;
}
#chat {
border : 0;
width: 500px;
}
#timer {
flex-grow: 1;
padding-top: 100px;
display: flex;
text-align: center;
flex-direction: column;
}
#countdown {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
font-size: 24vw;
font-family: monospace;
}
#current {
color: green;
}
#next {
color: yellow;
}
</style>
</head>
<body data-bs-theme="dark">
<iframe id="chat" src="https://twitch.tv/embed/anicloverclub/chat?parent=aniclover.com&darkpopout=1"></iframe>
<div id="timer">
<div>Current: <span id="current"></span> Next: <span id="next"></span></div>
<div id="countdown" >00:00</div>
<a id="editorlink">Edit Timetable</a>
</div>
<script type="text/javascript">
document.getElementById("editorlink").setAttribute("href", `editor.html${window.location.hash}`);
const timetable = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
function updateCountdown() {
const currentTime = Date.now();
let currentIdx = 0;
for (let i = 0; i < timetable.length; i++) {
if (timetable[i].start > currentTime)
break
currentIdx = i;
}
document.getElementById("current").innerText = timetable[currentIdx].name;
if (currentIdx != timetable.length - 1) {
document.getElementById("next").innerText = timetable[currentIdx + 1].name;
const durationToStart = (timetable[currentIdx + 1].start - currentTime) / 1000;
const minutesToStart = Math.floor(durationToStart / 60);
const secondsToStart = Math.floor(durationToStart % 60);
document.getElementById("countdown").innerText =
`${minutesToStart.toString().padStart(2, "0")}:${secondsToStart.toString().padStart(2, "0")}`;
if (minutesToStart < 5) {
document.getElementById("countdown").style["color"] = "orange";
} else {
document.getElementById("countdown").style["color"] = null;
}
} else {
document.getElementById("next").innerText = "none";
document.getElementById("countdown").innerText = "00:00";
}
}
updateCountdown();
setInterval(updateCountdown, 1000);
</script>
</body>
</html>