修改功能

This commit is contained in:
2026-08-29 19:06:07 +08:00
parent f94c652c7c
commit aaed0584b1
142 changed files with 6176 additions and 869 deletions
+90
View File
@@ -1,4 +1,94 @@
(function () {
function syncPublicNavigation() {
let token = "";
try {
token = window.localStorage.getItem("genealogy_auth_token") || "";
} catch (error) {
return;
}
if (!token) return;
document.querySelectorAll(".nav-actions").forEach((actions) => {
const loginLink = actions.querySelector('a[href="login.html"]');
const registerLink = actions.querySelector('a[href="register.html"]');
const createLink = actions.querySelector('a[href="create-genealogy.html"]');
if (loginLink) {
loginLink.href = "profile.html";
loginLink.textContent = "个人中心";
}
if (registerLink) {
registerLink.href = "profile-data.html";
registerLink.textContent = "账户资料";
}
if (createLink) createLink.href = "profile-create-family.html";
});
}
function initSiteMenu() {
const body = document.body;
const header = document.querySelector(".site-header");
const nav = header && header.querySelector(".nav");
const navLinks = nav && nav.querySelector(".nav-links");
const navActions = nav && nav.querySelector(".nav-actions");
if (!body || body.matches(".page-profile, .page-profile-module")) return;
if (!header || !nav || !navLinks || nav.querySelector("[data-site-menu-toggle]")) return;
const menuId = "site-mobile-menu";
const toggle = document.createElement("button");
const menu = document.createElement("div");
const inner = document.createElement("div");
toggle.className = "site-menu-toggle";
toggle.type = "button";
toggle.textContent = "菜单";
toggle.setAttribute("data-site-menu-toggle", "");
toggle.setAttribute("aria-expanded", "false");
toggle.setAttribute("aria-controls", menuId);
menu.className = "site-mobile-menu";
menu.id = menuId;
menu.hidden = true;
menu.setAttribute("data-site-mobile-menu", "");
menu.setAttribute("aria-hidden", "true");
inner.className = "container site-mobile-menu-inner";
[...navLinks.querySelectorAll("a"), ...(navActions ? navActions.querySelectorAll("a") : [])].forEach((link) => {
inner.appendChild(link.cloneNode(true));
});
menu.appendChild(inner);
nav.appendChild(toggle);
header.appendChild(menu);
body.classList.add("has-site-mobile-menu");
const setOpen = (isOpen) => {
menu.hidden = !isOpen;
menu.classList.toggle("is-open", isOpen);
menu.setAttribute("aria-hidden", isOpen ? "false" : "true");
toggle.setAttribute("aria-expanded", isOpen ? "true" : "false");
};
toggle.addEventListener("click", (event) => {
event.stopPropagation();
setOpen(toggle.getAttribute("aria-expanded") !== "true");
});
menu.addEventListener("click", (event) => {
if (event.target.closest("a")) setOpen(false);
event.stopPropagation();
});
document.addEventListener("click", () => setOpen(false));
document.addEventListener("keydown", (event) => {
if (event.key !== "Escape" || menu.hidden) return;
setOpen(false);
toggle.focus();
});
}
syncPublicNavigation();
initSiteMenu();
// 只在精确指针设备上启用微动效,触屏和减少动效偏好下保持静态。
const finePointer = window.matchMedia("(hover: hover) and (pointer: fine)").matches;
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;