jQuery(document).ready(function () { var $ = jQuery; function isAppleDevice() { return [ 'iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod' ].includes(navigator.platform) // iPad on iOS 13+ (pretends to be Mac but has touch) || (navigator.userAgent.includes("Mac") && "ontouchend" in document) // Real Macs (no touch) || (navigator.userAgent.includes("Macintosh") && !("ontouchend" in document)); } if (isAppleDevice()) { $('body').addClass('apple-device'); } function startCountdown() { const timers = $('.custom-countdown-timer'); if (timers.length === 0) { console.warn('No countdown timer elements found on the page.'); return; } try { // Define the start time in UTC and adjust to London time var londonStartTime = new Date(countdownSettings.startTimer); // Start time from settings console.log('Original Start Time:', londonStartTime); // London timezone offset (current) var londonOffset = new Date().getTimezoneOffset() - londonStartTime.getTimezoneOffset(); // Adjust the start time to London local time londonStartTime.setMinutes(londonStartTime.getMinutes() - londonOffset); console.log('Adjusted London Start Time:', londonStartTime); // Convert London start time to UTC timestamp var startTimer = londonStartTime.getTime(); console.log('Start Timer (UTC Milliseconds):', startTimer); // Restart duration in milliseconds var restartDuration = (countdownSettings.restartDurationHours * 60 + countdownSettings.restartDurationMinutes) * 60 * 1000; // Loop through each countdown timer timers.each(function () { var $timer = $(this); function updateCountdown() { // Get the current time in UTC and adjust for London time var currentDate = new Date(); currentDate.setMinutes(currentDate.getMinutes() - currentDate.getTimezoneOffset() + londonOffset); // Adjust to London time var currentDateMillis = currentDate.getTime(); var timeRemaining; if (currentDateMillis < startTimer) { timeRemaining = startTimer - currentDateMillis; // Time until countdown starts } else { var elapsed = currentDateMillis - startTimer; timeRemaining = restartDuration - (elapsed % restartDuration); // Remaining time until restart } // Convert timeRemaining to days, hours, minutes, and seconds var days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24)); var hours = Math.floor((timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000); // Update the timer elements $timer