This repository was archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
54 lines (51 loc) · 2.17 KB
/
index.html
File metadata and controls
54 lines (51 loc) · 2.17 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
<html>
<head>
<title>2Bored2Wait</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="content">
<button id="connectButton" class="start" onclick="start()">Connect</button><br><br>
</div>
<script>
setInterval(() => { //each second, update the info.
const xhr = new XMLHttpRequest();
xhr.open("GET", "/update", true);
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const response = JSON.parse(this.responseText);
const connectButton = document.getElementById('connectButton');
if (response.connected){
connectButton.innerHTML = "Disconnect";
connectButton.setAttribute('onclick', 'stop()');
connectButton.className = 'stop';
} else {
connectButton.innerHTML = "Connect";
connectButton.setAttribute('onclick', 'start()');
connectButton.className = 'start';
}
}
}
xhr.send();
}, 1000);
function start() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/start", true);
xhr.send();
const connectButton = document.getElementById('connectButton');
connectButton.innerHTML = "Disconnect";
connectButton.setAttribute('onclick', 'stop()');
connectButton.className = 'stop';
}
function stop() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/stop", true);
xhr.send();
const connectButton = document.getElementById('connectButton');
connectButton.innerHTML = "Connect";
connectButton.setAttribute('onclick', 'start()');
connectButton.className = 'start';
}
</script>
</body>
</html>