Files
web_hgtv_h5/app/static/js/pages/eightPop.js
T
谢宇宁andClaude Opus 5.5 3639d2184a Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:47:17 +07:00

63 lines
1.5 KiB
JavaScript

(function () {
var SESSION_KEY = "ageConfirmed";
var mask = document.getElementById("eightPop");
if (!mask) return;
function getSessionValue(key) {
try {
return window.sessionStorage.getItem(key) || "";
} catch (e) {
return "";
}
}
function setSessionValue(key, value) {
try {
window.sessionStorage.setItem(key, value);
} catch (e) {
// sessionStorage 不可用时,本页仍允许正常确认并关闭弹窗。
}
}
function openDialog() {
mask.hidden = false;
mask.removeAttribute("hidden");
mask.classList.add("is-open");
document.body.style.overflow = "hidden";
}
function closeDialog() {
mask.classList.remove("is-open");
mask.hidden = true;
mask.setAttribute("hidden", "");
document.body.style.overflow = "";
document.dispatchEvent(new CustomEvent("eightpop:closed"));
}
function confirmAge() {
setSessionValue(SESSION_KEY, "1");
closeDialog();
}
function exitSite() {
try {
window.location.replace("about:blank");
} catch (e) {
window.location.href = "about:blank";
}
}
var confirmBtn = mask.querySelector("[data-eight-pop-confirm]");
var exitBtns = mask.querySelectorAll("[data-eight-pop-exit]");
if (confirmBtn) {
confirmBtn.addEventListener("click", confirmAge);
}
exitBtns.forEach(function (button) {
button.addEventListener("click", exitSite);
});
if (getSessionValue(SESSION_KEY) !== "1") {
openDialog();
}
})();