This commit introduces functionality to display the store's open/closed status based on a schedule, with an override mechanism for holidays or emergencies. Changes include: - : Added IDs to hours paragraphs for easier manipulation. - : Refactored to be more robust and moved its logic to to prevent race conditions. Removed for status updates from . Fixed lightbox navigation. - : Added (boolean) and (string) fields to allow overriding the default status. - : Consolidated all status logic. It now acts as a gatekeeper: - If in is , it displays and ensures hours are visible. - If is , it runs the scheduled open/closed logic (originally from ) and updates the status every minute, ensuring hours are always visible. - : Reverted accidental changes and ensured only necessary status-related styles were added. This ensures: - The store's current open/closed status is always displayed. - An override message can be shown for special closures. - Store hours are always visible.
73 lines
2.6 KiB
JavaScript
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')
|
|
.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.';
|
|
}
|
|
});
|
|
});
|