uploaded base code

This commit is contained in:
2025-03-15 18:28:52 +02:00
parent dd379a6f5c
commit 4066abb255
10 changed files with 302 additions and 0 deletions

53
static/script.js Normal file
View File

@@ -0,0 +1,53 @@
const socket = io();
document.addEventListener("DOMContentLoaded", function () {
const storeForm = document.getElementById("store-form");
const phoneInput = document.getElementById("phone-input");
const retrieveButton = document.getElementById("retrieve-button");
const configForm = document.getElementById("config-form");
if (storeForm) {
storeForm.addEventListener("submit", function (event) {
event.preventDefault();
const formData = new FormData(storeForm);
fetch("/store", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(Object.fromEntries(formData))
})
.then(response => response.json())
.then(data => alert(data.message || "Error"));
});
}
if (retrieveButton) {
retrieveButton.addEventListener("click", function () {
const phone = phoneInput.value;
fetch(`/retrieve?phone=${encodeURIComponent(phone)}`)
.then(response => response.json())
.then(data => {
console.log(data);
alert(JSON.stringify(data));
});
});
}
if (configForm) {
configForm.addEventListener("submit", function (event) {
event.preventDefault();
const formData = new FormData(configForm);
fetch("/config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(Object.fromEntries(formData))
})
.then(response => response.json())
.then(data => alert(data.message || "Error"));
});
}
socket.on("update", function (data) {
console.log("Live update:", data);
alert(data.message);
});
});