test_app/frontend.js

21 lines
588 B
JavaScript
Raw Permalink Normal View History

2025-02-25 17:51:06 +02:00
function updateLights(state) {
document.getElementById("red").classList.toggle("red", state === "red");
document.getElementById("green").classList.toggle("green", state === "green");
}
function fetchStatus() {
fetch("/status")
.then(response => response.json())
.then(data => updateLights(data.state))
.catch(console.error);
}
function toggleLight() {
fetch("/toggle", { method: "POST" })
.then(response => response.json())
.then(data => updateLights(data.state))
.catch(console.error);
}
setInterval(fetchStatus, 1000);