-
Notifications
You must be signed in to change notification settings - Fork 1
/
chase-time-button.html
150 lines (136 loc) · 3.37 KB
/
chase-time-button.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chase Time Screen</title>
<style>
body {
font-family: Verdana, serif;
color: #fff;
font-size: 22px;
}
.bg {
width: 290px;
height: 100px;
border-radius: 20px;
position: relative;
}
.bg > span {
position: absolute;
left: 15px;
text-align: left;
top: 6px;
}
.killer {
position: absolute;
left: 11px;
height: 100px;
}
.title {
font-weight: bold;
color: #55CB8C;
text-shadow: 0 0 2px #38875c;
}
.count {
font-size: 48px;
color: #55CB8C;
text-shadow: 0 0 3px #38875c;
}
body {
background-color: #555555;
}
</style>
</head>
<body>
<div class="bg" id="whole">
<span class="text">
<span class="title">Chase Time</span><br>
<span class="count" id="timer">00:00</span><br>
<span>Screen is: <span id="isVisible">visible</span></span><br>
<button id="start">Start</button>
<button id="stop">Stop</button>
<button id="hide">Hide</button>
</span>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.1.2/socket.io.min.js" integrity="sha512-2ho+gY0H62N4Z9oxD422L2ZYXiOMq9l+Aub1QNz4Z4UDOtDVxz4vk6O6R3Hqqc9Y7qSvZFl7cy3+eZ/ITnUrLA==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.26.0/axios.min.js" integrity="sha512-bPh3uwgU5qEMipS/VOmRqynnMXGGSRv+72H/N260MQeXZIK4PG48401Bsby9Nq5P5fz7hy5UGNmC/W1Z51h2GQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script> // https://jsfiddle.net/bc_rikko/qwbfkv6y/2/
(async () => {
document.getElementById("start").addEventListener("click", (e) => {
e.preventDefault();
axios.get("/api/timer/start")
})
document.getElementById("stop").addEventListener("click", (e) => {
e.preventDefault();
axios.get("/api/timer/stop")
})
document.getElementById("hide").addEventListener("click", (e) => {
e.preventDefault();
axios.get("/api/timer/hide")
})
let timerData = {};
let started = 0;
const timer = document.getElementById("timer");
const whole = document.getElementById("whole");
const isVisible = document.getElementById("isVisible");
const result = await axios.get("/data/timer");
timerData = result.data;
started = result.data.started;
update()
const socket = io();
socket.on('timer', function (data) {
timerData = data;
update();
});
socket.on('data', function (data) {
if (data === "refresh") {
location.reload();
}
});
function update() {
if(timerData.justStarted) {
started = new Date().getTime();
}
if(timerData.isRunning) {
//whole.style.display = 'block';
isVisible.innerText = "visible";
}
if(timerData.isVisible) {
//whole.style.display = 'block';
isVisible.innerText = "visible";
} else {
//whole.style.display = 'none';
isVisible.innerText = "hidden";
}
updateTimer()
}
setInterval(() => {
if(timerData.isRunning) {
updateTimer();
}
}, 200)
function updateTimer() {
if(timerData.started) {
let now = new Date().getTime();
let difference = now - started;
let seconds = Math.floor(difference/1000);
let minutes = 0;
if(seconds >= 60) {
minutes = Math.floor(seconds/60);
seconds = seconds%60;
}
timer.innerText = `${pad(minutes)}:${pad(seconds)}`;
} else {
timer.innerText = '00:00';
}
}
function pad(number) {
if(number < 10) {
return '0' + number;
}
return number+'';
}
})()
</script>
</html>