// 1. Read Configuration const config = window.SeasonalsPluginConfig?.EarthDay || {}; const enabled = config.EnableEarthDay !== undefined ? config.EnableEarthDay : true; const vineCount = config.VineCount || 4; let msgPrinted = false; // 2. Toggle Function function toggleEarthDay() { const container = document.querySelector('.earthday-container'); if (!container) return; const videoPlayer = document.querySelector('.videoPlayerContainer'); const trailerPlayer = document.querySelector('.youtubePlayerContainer'); const isDashboard = document.body.classList.contains('dashboardDocument'); const hasUserMenu = document.querySelector('#app-user-menu'); if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) { container.style.display = 'none'; if (!msgPrinted) { console.log('EarthDay hidden'); msgPrinted = true; } } else { container.style.display = 'block'; if (msgPrinted) { console.log('EarthDay visible'); msgPrinted = false; } } } // 3. MutationObserver const observer = new MutationObserver(toggleEarthDay); observer.observe(document.body, { childList: true, subtree: true, attributes: true }); // 4. Element Creation function createElements() { const container = document.querySelector('.earthday-container') || document.createElement('div'); if (!document.querySelector('.earthday-container')) { container.className = 'earthday-container'; container.setAttribute('aria-hidden', 'true'); document.body.appendChild(container); } const w = window.innerWidth; const hSVG = Math.floor(window.innerHeight * 0.15) || 100; // 15vh roughly let paths = ''; // Generate Grass for (let i = 0; i < 400; i++) { const x = Math.random() * w; const h = hSVG * 0.2 + Math.random() * (hSVG * 0.8); const cY = hSVG - h; const bend = x + (Math.random() * 40 - 20); const color = Math.random() > 0.5 ? '#2E8B57' : '#3CB371'; const width = 1 + Math.random() * 2; paths += ``; } // Generate Flowers const colors = ['#FF69B4', '#FFD700', '#87CEFA', '#FF4500', '#BA55D3', '#FFA500', '#FF1493']; const flowerCount = Math.max(10, vineCount * 15); for (let i = 0; i < flowerCount; i++) { const x = 10 + Math.random() * (w - 20); const y = hSVG * 0.1 + Math.random() * (hSVG * 0.5); const col = colors[Math.floor(Math.random() * colors.length)]; paths += ``; const r = 2 + Math.random() * 1.5; paths += ``; paths += ``; paths += ``; paths += ``; paths += ``; } const svgContent = ` ${paths} `; container.innerHTML = svgContent; } // 5. Responsive Resize function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } const handleResize = debounce(() => { const container = document.querySelector('.earthday-container'); if (container) { container.innerHTML = ''; createElements(); } }, 250); window.addEventListener('resize', handleResize); // 6. Initialization function initializeEarthDay() { if (!enabled) return; createElements(); toggleEarthDay(); } initializeEarthDay();