-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhappyhour.html
More file actions
93 lines (81 loc) · 2.18 KB
/
happyhour.html
File metadata and controls
93 lines (81 loc) · 2.18 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
93
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Happy Hour Status</title>
<style>
body {
margin: 0;
background: rgba(0,0,0,0);
font-family: Arial, sans-serif;
overflow: hidden;
padding: 6px 10px;
}
#hhBox {
color: #ffcc00; /* same yellow as .headline */
font-weight: bold; /* same weight */
font-size: 17px; /* same size */
display: inline-block;
line-height: 1.2em;
white-space: nowrap;
visibility: hidden; /* hidden when no text */
}
</style>
</head>
<body>
<div id="hhBox"></div>
<script>
const BASE = "http://subathon.smtxlost.tv:5000";
let happyActive = false;
let happyRemaining = 0;
let happyMultiplier = 1;
// Format seconds into mm:ss or hh:mm:ss
function fmt(sec) {
if (sec >= 3600) {
let h = Math.floor(sec / 3600);
let m = Math.floor((sec % 3600) / 60);
let s = sec % 60;
return `${String(h).padStart(2,"0")}:${String(m).padStart(2,"0")}:${String(s).padStart(2,"0")}`;
} else {
let m = Math.floor(sec / 60);
let s = sec % 60;
return `${String(m).padStart(2,"0")}:${String(s).padStart(2,"0")}`;
}
}
// Poll Happy Hour status
function loadHH() {
fetch(BASE + "/happyhour")
.then(r => r.json())
.then(d => {
happyActive = d.active;
happyRemaining = d.remaining_seconds;
happyMultiplier = d.multiplier;
updateBox();
})
.catch(() => {});
}
// Update the display
function updateBox() {
const box = document.getElementById("hhBox");
if (!happyActive) {
box.innerText = "";
box.style.visibility = "hidden"; // hide completely
return;
}
box.innerText = `Happy Hour x${happyMultiplier} - ${fmt(happyRemaining)}`;
box.style.visibility = "visible";
}
// Local countdown
setInterval(() => {
if (happyActive && happyRemaining > 0) {
happyRemaining--;
updateBox();
}
}, 1000);
// Poll every 5 sec
setInterval(loadHH, 5000);
// Initial load
loadHH();
</script>
</body>
</html>