// Dynamic content v1.0.1 // - Displays content with the most recent activeDate <= current time // - Test with ?today=01/01/2025+18:00:00 // Convert a date string or Date object to Eastern Time function toEasternTime(input) { return new Date( new Date(input).toLocaleString('en-US', { timeZone: 'America/New_York' }) ); } var params = new URLSearchParams(window.location.search); var todayParam = params.get('today'); var cNow = todayParam ? toEasternTime(decodeURIComponent(todayParam)) : toEasternTime(new Date()); // Collect and map active elements with parsed Eastern Time dates var dateElements = Array.from(document.querySelectorAll('[data-active-date]')).map(function(el) { return { el: el, date: toEasternTime(el.dataset.activeDate) }; }); // Sort ascending dateElements.sort(function(a, b) { return a.date - b.date; }); // Find most recent matching element var matched = null; for (var i = 0; i < dateElements.length; i++) { if (cNow >= dateElements[i].date) matched = dateElements[i]; else break; } // Show matched, remove others for (var j = 0; j < dateElements.length; j++) { var el = dateElements[j].el; var date = dateElements[j].date; if (matched && date.getTime() === matched.date.getTime()) { el.style.display = 'block'; el.removeAttribute('data-active-date'); // Apply data-e-video-id to any .e-video child var videoId = el.getAttribute('data-active-video-id'); if (videoId) { var video = el.querySelector('.e-video'); if (video) { video.setAttribute('data-e-video-id', videoId); } } // Remove the data-active-video-id from the parent el.removeAttribute('data-active-video-id'); } else { el.remove(); } }