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') .then(response => response.json()) .then(data => { const update = data[0]; // Handle the top message if (update.message && update.message.trim() !== "") { 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.'; } }); });