// URL params const urlParams = new URLSearchParams(window.location.search); const queryTheme = urlParams.get('theme'); const queryFlip = urlParams.get('flip'); const queryRef = urlParams.get('ref'); // Get stored theme and theme slider const currentTheme = localStorage.getItem('theme'); const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]'); // Apply and save theme function applyTheme(t) { document.documentElement.setAttribute('data-theme', t); localStorage.setItem('theme', t); } // Load theme if (queryTheme) { if (queryTheme === 'dark') { applyTheme('dark'); toggleSwitch.checked = true; } else { applyTheme('light'); toggleSwitch.checked = false; } } else if (currentTheme) { if (currentTheme === 'dark') { applyTheme('dark'); toggleSwitch.checked = true; } else { applyTheme('light'); toggleSwitch.checked = false; } } else { applyTheme('light'); toggleSwitch.checked = false; } // Theme toggle switch function switchTheme(e) { if (e.target.checked) { applyTheme('dark'); } else { applyTheme('light'); } } // Bind toggle switch function toggleSwitch.addEventListener('change', switchTheme, false); // Set initial card flip if (queryFlip) { const elements = document.getElementsByClassName('flip-inner'); for (let i = 0; i < elements.length; i++) { elements[i].classList.add("flipped"); } } // Log referral code if (queryRef) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'ref_link_click', 'ref_code': queryRef, }); }