update open status js
This commit is contained in:
parent
3e895307d9
commit
fa6a499de8
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"liveServer.settings.port": 5511
|
"liveServer.settings.port": 5514
|
||||||
}
|
}
|
||||||
64
script.js
64
script.js
@ -179,27 +179,49 @@ function topFunction() {
|
|||||||
|
|
||||||
function updateBusinessHours() {
|
function updateBusinessHours() {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const nowUtc = new Date(now.getTime() + now.getTimezoneOffset() * 60000); // Convert to UTC
|
if (document.body.scrollTop > 130 || document.documentElement.scrollTop > 130) {
|
||||||
const newYorkTime = new Date(nowUtc.getTime() + 5 * 60 * 60 * 1000); // Convert to New York time
|
mybutton.style.display = "block";
|
||||||
|
} else {
|
||||||
const today = newYorkTime.getDay(); // Get day of the week (0 = Sunday, ..., 6 = Saturday)
|
mybutton.style.display = "none";
|
||||||
const currentHour = newYorkTime.getHours(); // Get hour in 24-hour format
|
|
||||||
|
|
||||||
if (today >= 1 && today <= 5) { // Monday to Friday
|
|
||||||
if (currentHour >= 10 && currentHour < 17) {
|
|
||||||
// document.getElementById('neon').classList.remove('neonTextClosed');
|
|
||||||
// document.getElementById('neon').classList.add('neonTextOpen');
|
|
||||||
document.getElementById('status').textContent = 'We are currently OPEN.';
|
|
||||||
} else {
|
|
||||||
// document.getElementById('neon').classList.remove('neonTextOpen');
|
|
||||||
// document.getElementById('neon').classList.add('neonTextClosed');
|
|
||||||
document.getElementById('status').textContent = 'We are currently CLOSED.';
|
|
||||||
}
|
|
||||||
} else { // Saturday or Sunday
|
|
||||||
// document.getElementById('neon').classList.remove('neonTextOpen');
|
|
||||||
// document.getElementById('neon').classList.add('neonTextClosed');
|
|
||||||
document.getElementById('status').textContent = 'We are currently CLOSED.';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBusinessHours();
|
// When the user clicks on the button, scroll to the top of the document
|
||||||
|
function topFunction() {
|
||||||
|
document.body.scrollTop = 0; // For Safari
|
||||||
|
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE, and Opera
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open/closed sign function
|
||||||
|
function checkStatus() {
|
||||||
|
const now = new Date();
|
||||||
|
const checkHour = now.getHours();
|
||||||
|
let isOpen = false;
|
||||||
|
|
||||||
|
// Define days of operation
|
||||||
|
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
||||||
|
const currentDay = daysOfWeek[now.getDay()];
|
||||||
|
|
||||||
|
const operatingHours = {
|
||||||
|
"Saturday": { start: 9, end: 15 },
|
||||||
|
"Tuesday": { start: 10, end: 17 },
|
||||||
|
"Wednesday": { start: 10, end: 17 },
|
||||||
|
"Thursday": { start: 10, end: 17 }
|
||||||
|
};
|
||||||
|
|
||||||
|
if (currentDay === "Sunday") {
|
||||||
|
isOpen = false; // Store is closed on Sundays
|
||||||
|
} else if (operatingHours[currentDay]) {
|
||||||
|
const { start, end } = operatingHours[currentDay];
|
||||||
|
isOpen = checkHour >= start && checkHour < end;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the status in the HTML
|
||||||
|
const statusElement = document.getElementById("status");
|
||||||
|
if (statusElement) {
|
||||||
|
statusElement.textContent = isOpen ? "We are currently OPEN" : "We are currently CLOSED";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update status every second
|
||||||
|
setInterval(checkStatus, 1000);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user