1(function () { 2 var COOKIE_ACCEPT = 'accept_cookies'; 3 var COOKIE_INTERNAL = 'internal_cookies'; 4 var STORAGE_KEY = 'nieuwsned_cookie_consent'; 5 6 function getCookie(name) { 7 var cookies = document.cookie ? document.cookie.split(';') : []; 8 for (var i = 0; i < cookies.length; i++) { 9 var parts = cookies[i].split('='); 10 if (parts[0] && parts[0].trim() === name) { 11 return decodeURIComponent((parts[1] || '').trim()); 12 } 13 } 14 return null; 15 } 16 17 function setCookie(name, value, days) { 18 var maxAge = Math.max(1, Math.floor(days * 24 * 60 * 60)); 19 var secure = window.location.protocol === 'https:' ? '; Secure' : ''; 20 document.cookie = name + '=' + encodeURIComponent(value) + '; path=/; max-age=' + maxAge + '; SameSite=Lax' + secure; 21 } 22 23 function deleteCookie(name) { 24 var secure = window.location.protocol === 'https:' ? '; Secure' : ''; 25 document.cookie = name + '=; path=/; max-age=0; SameSite=Lax' + secure; 26 } 27 28 function hasConsent() { 29 var accept = getCookie(COOKIE_ACCEPT); 30 var internal = getCookie(COOKIE_INTERNAL); 31 if (accept || internal) { 32 return true; 33 } 34 try { 35 return !!window.localStorage.getItem(STORAGE_KEY); 36 } catch (e) { 37 return false; 38 } 39 } 40 41 function saveConsent(consentValue) { 42 setCookie(COOKIE_ACCEPT, consentValue, 365); 43 if (consentValue === 'internal') { 44 setCookie(COOKIE_INTERNAL, 'true', 365); 45 } else { 46 deleteCookie(COOKIE_INTERNAL); 47 } 48 try { 49 window.localStorage.setItem(STORAGE_KEY, consentValue); 50 } catch (e) { 51 // ignore storage failures (private mode, blocked storage) 52 } 53 } 54 55 function syncServer(endpoint) { 56 fetch(endpoint, { 57 method: 'GET', 58 credentials: 'same-origin', 59 cache: 'no-store', 60 headers: { 'X-Requested-With': 'XMLHttpRequest' } 61 }).catch(function () { 62 // client-side cookie/localStorage already set; ignore network errors 63 }); 64 } 65 66 function setBannerVisible(visible) { 67 var banner = document.getElementById('cookie_banner'); 68 if (!banner) { 69 return; 70 } 71 banner.style.display = visible ? 'block' : 'none'; 72 } 73 74 window.addEventListener('DOMContentLoaded', function () { 75 var acceptButton = document.getElementById('accept_cookies'); 76 var denyButton = document.getElementById('internal_cookies'); 77 78 setBannerVisible(!hasConsent()); 79 80 if (acceptButton) { 81 acceptButton.addEventListener('click', function () { 82 saveConsent('true'); 83 setBannerVisible(false); 84 syncServer('/accept_cookies'); 85 window.dispatchEvent(new Event('nieuwsned:external-consent')); 86 }); 87 } 88 89 if (denyButton) { 90 denyButton.addEventListener('click', function () { 91 saveConsent('internal'); 92 setBannerVisible(false); 93 syncServer('/deny_external_cookies'); 94 }); 95 } 96 }); 97})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.