51 lines
1.9 KiB
HTML
51 lines
1.9 KiB
HTML
<script>
|
|
// Wir nutzen relative Pfade (ohne führenden Slash),
|
|
// damit Ingress den Pfad korrekt auflöst.
|
|
async function update() {
|
|
try {
|
|
const res = await fetch('api/status'); // Geändert von /api/status
|
|
if (!res.ok) throw new Error('Network error');
|
|
|
|
const data = await res.json();
|
|
const statusEl = document.getElementById('status');
|
|
const qrSection = document.getElementById('qr-section');
|
|
|
|
if (data.isReady) {
|
|
statusEl.innerText = "CONNECTED ✅";
|
|
statusEl.className = "status-badge connected";
|
|
qrSection.style.display = "none";
|
|
} else if (data.hasQr) {
|
|
statusEl.innerText = "WAITING FOR SCAN 📱";
|
|
statusEl.className = "status-badge disconnected";
|
|
qrSection.style.display = "block";
|
|
document.getElementById('qr-code').innerHTML = `<img src="${data.qrCode}">`;
|
|
} else {
|
|
statusEl.innerText = "INITIALIZING...";
|
|
qrSection.style.display = "none";
|
|
}
|
|
} catch (e) {
|
|
console.error("Update failed", e);
|
|
document.getElementById('status').innerText = "OFFLINE ❌";
|
|
}
|
|
}
|
|
|
|
async function cmd(url, method, msg) {
|
|
if (!confirm(msg)) return;
|
|
document.getElementById('msg').innerText = "Working...";
|
|
|
|
// Auch hier: Slash am Anfang entfernen für relative Pfade
|
|
const relativeUrl = url.startsWith('/') ? url.substring(1) : url;
|
|
|
|
try {
|
|
const res = await fetch(relativeUrl, { method });
|
|
const data = await res.json();
|
|
alert(data.message);
|
|
location.reload();
|
|
} catch (e) {
|
|
alert("Error: " + e.message);
|
|
}
|
|
}
|
|
|
|
setInterval(update, 3000);
|
|
update();
|
|
</script> |