34 lines
923 B
JavaScript
34 lines
923 B
JavaScript
const COOKIE_NOTICE_KEY = "siteCookieConsentV1";
|
|
|
|
export function initCookieNotice() {
|
|
const notice = document.querySelector("[data-cookie-notice]");
|
|
const acceptBtn = document.querySelector("[data-cookie-accept]");
|
|
const policyLink = document.querySelector("[data-cookie-policy-link]");
|
|
if (!notice || !acceptBtn) return;
|
|
|
|
let accepted = false;
|
|
try {
|
|
accepted = localStorage.getItem(COOKIE_NOTICE_KEY) === "accepted";
|
|
} catch {
|
|
accepted = false;
|
|
}
|
|
|
|
notice.hidden = !!accepted;
|
|
|
|
acceptBtn.addEventListener("click", () => {
|
|
try {
|
|
localStorage.setItem(COOKIE_NOTICE_KEY, "accepted");
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
notice.hidden = true;
|
|
});
|
|
|
|
if (policyLink) {
|
|
const href = policyLink.getAttribute("href") || "";
|
|
if (href === "#" || href === "") {
|
|
policyLink.addEventListener("click", (e) => e.preventDefault());
|
|
}
|
|
}
|
|
}
|