chris ad5c984a46 Mirror live open/closed status to contact page
Add #status and #hours-* IDs to the contact page hours tile and load
update.js so the same live open/closed logic from the homepage runs
on the contact page. Guard against missing #message element so update.js
works on pages that don't have the marquee banner.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-12 19:45:21 -04:00

73 lines
2.6 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const message = document.getElementById('message');
const statusElement = document.getElementById('status');
const hoursTuesdayFriday = document.getElementById('hours-tuesday-friday');
const hoursSaturday = document.getElementById('hours-saturday');
const hoursSundayMonday = document.getElementById('hours-sunday-monday');
let statusInterval;
function checkStatus() {
const now = new Date();
const checkHour = now.getHours();
let isOpen = false;
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const currentDay = daysOfWeek[now.getDay()];
const operatingHours = {
"Sunday": { start: 0, end: 0 },
"Monday": { start: 0, end: 0 },
"Tuesday": { start: 10, end: 17 },
"Wednesday": { start: 10, end: 17 },
"Thursday": { start: 10, end: 17 },
"Friday": { start: 10, end: 17 },
"Saturday": { start: 9, end: 15 }
};
if (operatingHours[currentDay]) {
const { start, end } = operatingHours[currentDay];
isOpen = checkHour >= start && checkHour < end;
}
if (statusElement) {
statusElement.textContent = isOpen ? "We are currently OPEN" : "We are currently CLOSED";
}
}
fetch(`/update.json?ts=${Date.now()}`, { cache: 'no-store' })
.then(response => response.json())
.then(data => {
const update = data[0];
// Handle the top message
if (update.message && update.message.trim() !== "") {
if (message) message.textContent = update.message;
} else {
const updateElement = document.querySelector('.update');
if (updateElement) {
updateElement.style.display = "none";
}
}
// Handle the closed override and regular status
if (update.isClosed) {
if (statusInterval) {
clearInterval(statusInterval);
}
if (statusElement) {
statusElement.textContent = update.closedMessage;
}
} else {
checkStatus(); // Initial check
statusInterval = setInterval(checkStatus, 60000); // Update every minute
}
})
.catch(error => {
console.error('Error fetching data:', error);
if (statusElement) {
statusElement.textContent = 'Error loading status.';
}
});
});