buzzer/data/www/script.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

function play() {
console.log("Play...");
2023-01-01 18:32:23 +01:00
fetch("/play", { signal: AbortSignal.timeout(7000) });
}
2023-01-01 02:43:54 +01:00
function loadAvailableFiles() {
console.log("Available files...");
2023-01-01 18:32:23 +01:00
fetch("/available-files", { signal: AbortSignal.timeout(7000) })
2023-01-01 02:43:54 +01:00
.then(response => response.json())
2023-01-01 02:55:32 +01:00
.then(handleAvailableFiles);
2023-01-01 02:43:54 +01:00
}
function selectFile(name) {
console.log("Select file");
const body = new FormData();
body.set("fileName", name);
2023-01-01 18:32:23 +01:00
fetch("/select-file", { method: "POST", body: body, signal: AbortSignal.timeout(7000) })
2023-01-01 02:55:32 +01:00
.then(response => response.json())
.then(handleAvailableFiles);
}
function handleAvailableFiles(data) {
console.log("data", data);
let dom = "";
data.files.forEach(element => {
if (element === data.selectedFile) {
dom += `<button class="w3-button w3-green" onclick="selectFile('${element}')">${element}</button>`;
}
else {
dom += `<button class="w3-button w3-blue" onclick="selectFile('${element}')">${element}</button>`;
}
});
document.getElementById("available-files").innerHTML = dom;
2023-01-01 02:43:54 +01:00
}
(() => {
loadAvailableFiles();
2023-01-01 18:14:41 +01:00
setInterval(loadAvailableFiles, 10000);
2023-01-01 02:43:54 +01:00
})();