Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,79 @@
</head>

<body>
<h3 id="isOff" style="display: none">Sign is Off</h3>
<marquee
id="sign-preview"
direction="left"
style="
width: 150px;
border-style: solid;
border-width: 5px;
font-family: monospace;
font-size: 20px;
"
/>
<div style="max-width: 700px; margin: 40px auto; text-align: center;">
<div style="text-align: left; font-size: 1.5em; margin-bottom: 8px; color: #23292c;">Preview</div>
<div id="sign-preview" style="background: #eae6de; color: #23302c; border: 6px solid #d32f2f; border-radius: 14px; font-size: 3em; font-family: 'Arial Rounded MT Bold', Arial, sans-serif; font-weight: bold; text-align: center; padding: 20px 0; margin: 0 auto 32px auto; box-sizing: border-box; width: 100%; box-shadow: 0 2px 8px #d32f2f33;"> </div>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we check if all of these classes are required, if not let's try to remove whatever is not necessary

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i checked and removed some unnecessary parts

<form id="update-form" style="margin: 0 auto; display: inline-block; text-align: left;">
<h3>Update Sign (Debug)</h3>
<label>Text: <input type="text" name="text" required></label><br>
<label>Background Color: <input type="color" name="backgroundColor" value="#eae6de" style="width: 60px;"></label><br>
<label>Text Color: <input type="color" name="textColor" value="#23302c" style="width: 60px;"></label><br>
<label>Border Color: <input type="color" name="borderColor" value="#d32f2f" style="width: 60px;"></label><br>
<label>Scroll Speed: <input type="text" name="scrollSpeed" value="50"></label><br>
<label>Brightness: <input type="text" name="brightness" value="100"></label><br>
<button type="submit">Update Sign</button>
</form>
<div id="update-message" style="margin-top:10px;color:#d32f2f;font-weight:bold;"></div>
</div>

<script>
const handleFetch = async () => {
url = new URL("health-check", window.location.origin);
const url = new URL("health-check", window.location.origin);
try {
const res = await fetch(url.href);
if (!res.ok) {
throw new Error("Could not fetch resource");
}

const data = await res.json();

const sign = document.getElementById("sign-preview");
console.log(Object.hasOwn(data, "text"));

if (!Object.hasOwn(data, "text")) {
document.getElementById("sign-preview").style.display = "none";

document.getElementById("isOff").style.display = "block";
sign.textContent = "Sign is Off";
sign.style.background = "#eae6de";
sign.style.color = "#23302c";
sign.style.borderColor = "#d32f2f";
return;
}
document.getElementById("sign-preview").style.color = data.textColor;
document.getElementById("sign-preview").style.backgroundColor =
data.backgroundColor;
document.getElementById("sign-preview").style.borderColor =
data.borderColor;
document.getElementById("sign-preview").innerHTML = data.text;
document
.getElementById("sign-preview")
.setAttribute("scrollamount", data.scrollSpeed);
sign.textContent = data.text;
sign.style.background = data.backgroundColor;
sign.style.color = data.textColor;
sign.style.borderColor = data.borderColor;
} catch (err) {
console.log(err);
}
};
handleFetch();
document.getElementById('update-form').onsubmit = async function(e) {
e.preventDefault();
const form = e.target;
const payload = {
text: form.text.value,
backgroundColor: form.backgroundColor.value,
textColor: form.textColor.value,
borderColor: form.borderColor.value,
scrollSpeed: Number(form.scrollSpeed.value),
brightness: form.brightness.value ? Number(form.brightness.value) : 100
};
try {
const res = await fetch('/update-sign', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (res.ok) {
document.getElementById('update-message').textContent = 'Sign updated';
setTimeout(() => { document.getElementById('update-message').textContent = ''; }, 1500);
setTimeout(handleFetch, 500);
} else {
document.getElementById('update-message').textContent = 'Failed to update sign';
}
} catch (err) {
document.getElementById('update-message').textContent = 'Error updating sign';
}
};
</script>
</body>
</html>