// Function to set a cookie function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } // Function to get a cookie function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } document.addEventListener("DOMContentLoaded", function () { const banner = document.getElementById("cookie-banner"); const btn = document.getElementById("cookie-ok-btn"); // Show the banner only if the cookie doesn't exist if (!getCookie("cookieAccepted")) { banner.style.display = "block"; let scrollTimeout = null; let alreadyAccepted = false; // Function to accept cookies function acceptCookies() { if (alreadyAccepted) return; alreadyAccepted = true; setCookie("cookieAccepted", "true", 365); // Add fade-out class banner.classList.add("fade-out"); // Wait for the transition to end before hiding the banner setTimeout(() => { banner.style.display = "none"; }, 500); // same duration as CSS transition } // On scroll, start timeout to accept cookies function onScroll() { if (scrollTimeout) return; scrollTimeout = setTimeout(acceptCookies, 15000); } // Accept on button click btn.addEventListener("click", acceptCookies); // Accept after scrolling document.addEventListener("scroll", onScroll); // Accept on any click on the page document.addEventListener("click", acceptCookies); } });