Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
(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();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user