function setCookie(name, value, exp) { let data = new Date(); data.setTime(data.getTime() + exp * 24 * 60 * 60 * 1000); document.cookie = name + '=' + value + ';expires=' + data.toUTCString() + ';path=/'; } function getTerm(value) { switch (value) { case 'day': return 1; case 'week': return 7; case 'month': return 30; default: return 0; } } document.addEventListener('DOMContentLoaded', () => { const closes = document.querySelectorAll(".close"); closes.forEach((box) => { box.addEventListener("click", () => { const checkbox = box.parentNode.querySelector('.chk_close'); if (checkbox.checked) { setCookie('pop' + checkbox.dataset.idx, '1', getTerm(checkbox.value)); } box.parentNode.parentNode.style.display = 'none'; }); }); const textCloses = document.querySelectorAll('.text-close'); textCloses.forEach((text) => { text.addEventListener("click", () => { const checkbox = text.parentNode.querySelector('.chk_close'); if (checkbox.checked) { setCookie('pop' + checkbox.dataset.idx, '1', getTerm(checkbox.value)); } text.parentNode.parentNode.style.display = 'none'; }); }); });