mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
35 lines
873 B
JavaScript
35 lines
873 B
JavaScript
const form = document.querySelector("form");
|
|
|
|
async function loadData() {
|
|
try {
|
|
const req = await fetch("/config", {
|
|
method: "GET",
|
|
});
|
|
if (!req.ok) {
|
|
throw new Error(`Response status: ${req.status}`);
|
|
}
|
|
|
|
const json = await req.json();
|
|
console.log(json);
|
|
return json;
|
|
} catch (error) {
|
|
console.log(error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function writeDataToInput(data) {
|
|
console.log("write data", typeof data);
|
|
for (const [key, value] of Object.entries(data)) {
|
|
const element = document.querySelector(`[name=${key}]`);
|
|
console.log(element);
|
|
element.value = value;
|
|
}
|
|
// send "change" event
|
|
form.dispatchEvent(new Event("change", { bubbles: true }));
|
|
}
|
|
|
|
const data = await loadData();
|
|
if (data !== null) {
|
|
writeDataToInput(data);
|
|
}
|