55 lines
1.4 KiB
HTML
55 lines
1.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<header>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/light.css">
|
|
</header>
|
|
<body>
|
|
<h1>Hello World</h1>
|
|
</body>
|
|
<footer>
|
|
<script>
|
|
let g_questions = [];
|
|
let g_live_question = {};
|
|
|
|
function pollState() {
|
|
http("GET", "/api/v1/questions", (body) => {
|
|
g_questions = JSON.parse(body);
|
|
console.log("polled state:", body);
|
|
pollLiveAnswer();
|
|
pollLiveQuestion();
|
|
});
|
|
}
|
|
|
|
function pollLiveQuestion() {
|
|
let live_questions = g_questions.filter((q) => q.Live);
|
|
if (live_questions) {
|
|
g_live_question = live_questions[0];
|
|
}
|
|
}
|
|
|
|
function pollLiveAnswer() {
|
|
if (!g_live_question || !g_live_question.Closed) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
function http(method, remote, callback, body) {
|
|
var xmlhttp = new XMLHttpRequest();
|
|
xmlhttp.onreadystatechange = function() {
|
|
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
|
callback(xmlhttp.responseText, xmlhttp.status)
|
|
}
|
|
};
|
|
xmlhttp.open(method, remote, true);
|
|
if(typeof body == "undefined") {
|
|
body = null
|
|
}
|
|
xmlhttp.send(body);
|
|
}
|
|
|
|
pollState();
|
|
setInterval(() => { pollState(); }, 1000);
|
|
</script>
|
|
</footer>
|
|
</html>
|