יום חמישי, 29 בינואר 2026
טוען מזג אוויר...
\n \n "}]}; const LOADED_SCRIPTS = {}; // Get stored consent function getConsent() { try { const stored = localStorage.getItem(CONSENT_KEY); if (stored) { const consent = JSON.parse(stored); if (consent.version === CONSENT_VERSION) { return consent; } } } catch (e) {} return null; } // Save consent function saveConsent(preferences) { const consent = { version: CONSENT_VERSION, timestamp: Date.now(), preferences: preferences }; localStorage.setItem(CONSENT_KEY, JSON.stringify(consent)); // Dispatch event for other scripts to react window.dispatchEvent(new CustomEvent('cookieConsentChanged', { detail: consent })); // Load scripts based on new consent loadTrackingScripts(preferences); } // Load tracking scripts based on consent function loadTrackingScripts(preferences) { if (!TRACKING_CONFIG || !TRACKING_CONFIG.services) return; TRACKING_CONFIG.services.forEach(function(service) { // Skip if already loaded if (LOADED_SCRIPTS[service.key]) return; // Check if user consented to this category if (!preferences[service.category]) { console.log('[Tracking] Skipping ' + service.name + ' - no consent for ' + service.category); return; } // Load the script console.log('[Tracking] Loading ' + service.name); LOADED_SCRIPTS[service.key] = true; // Create a container for the scripts var container = document.createElement('div'); container.innerHTML = service.script; // Process script tags (they won't execute if just innerHTML'd) var scripts = container.querySelectorAll('script'); scripts.forEach(function(oldScript) { var newScript = document.createElement('script'); // Copy attributes Array.from(oldScript.attributes).forEach(function(attr) { newScript.setAttribute(attr.name, attr.value); }); // Copy inline script content if (oldScript.innerHTML) { newScript.innerHTML = oldScript.innerHTML; } // Append to head document.head.appendChild(newScript); }); // Handle noscript content (for pixels that have noscript fallbacks) var noscripts = container.querySelectorAll('noscript'); noscripts.forEach(function(ns) { // Append noscript content as-is to body var div = document.createElement('div'); div.innerHTML = ns.innerHTML; document.body.appendChild(div); }); }); } // Show banner function showBanner() { const banner = document.getElementById('cookie-consent-banner'); if (banner) { banner.style.display = 'block'; } } // Hide banner function hideBanner() { const banner = document.getElementById('cookie-consent-banner'); if (banner) { banner.style.display = 'none'; } } // Show modal function showModal() { const modal = document.getElementById('cookie-settings-modal'); if (modal) { modal.style.display = 'flex'; document.body.style.overflow = 'hidden'; // Load current preferences const consent = getConsent(); if (consent) { document.getElementById('cookie-analytics').checked = consent.preferences.analytics; document.getElementById('cookie-marketing').checked = consent.preferences.marketing; } } } // Hide modal function hideModal() { const modal = document.getElementById('cookie-settings-modal'); if (modal) { modal.style.display = 'none'; document.body.style.overflow = ''; } } // Accept all cookies function acceptAll() { saveConsent({ essential: true, analytics: true, marketing: true }); hideBanner(); hideModal(); } // Accept essential only function acceptEssential() { saveConsent({ essential: true, analytics: false, marketing: false }); hideBanner(); hideModal(); } // Save custom preferences function savePreferences() { saveConsent({ essential: true, analytics: document.getElementById('cookie-analytics').checked, marketing: document.getElementById('cookie-marketing').checked }); hideBanner(); hideModal(); } // Initialize function init() { const consent = getConsent(); if (!consent) { // No consent yet, show banner showBanner(); } else { // Consent exists, load allowed scripts loadTrackingScripts(consent.preferences); } // Event listeners document.getElementById('cookie-accept-all')?.addEventListener('click', acceptAll); document.getElementById('cookie-accept-essential')?.addEventListener('click', acceptEssential); document.getElementById('cookie-settings')?.addEventListener('click', showModal); document.getElementById('cookie-modal-close')?.addEventListener('click', hideModal); document.getElementById('cookie-save-preferences')?.addEventListener('click', savePreferences); // Close modal on overlay click document.querySelector('.cookie-modal-overlay')?.addEventListener('click', hideModal); // Close modal on Escape key document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { hideModal(); } }); } // Run when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } // Expose API for other scripts window.CookieConsent = { getConsent: getConsent, showBanner: showBanner, showSettings: showModal, hasConsent: function(type) { const consent = getConsent(); return consent && consent.preferences[type]; }, // Allow manual reload of scripts (e.g., after settings change) reloadScripts: function() { const consent = getConsent(); if (consent) { loadTrackingScripts(consent.preferences); } } }; })();