(() => {
/**
* ── 導覽「尚未開放」連結 ─────────────────────────────────────────
* ① 整個檔案先關:COMING_SOON_PAGES(目前已含志源頁/演唱會/典藏/地圖/視覺進化論等)。
* ② index.html 細到錨點:INDEX_NAV_OPEN_HASHES。
* ③ 文案 NAV_SOON_PHRASES:每次「滑過或鍵盤聚焦」連結時隨機擇一句(不交錯只靠重整)。
* 浮層、title 與該次互動同步;無障礙用語固定為「尚無開放」(避免標籤隨機跳動)。
* 要調整詞句:改 NAV_SOON_PHRASES 即可。
*/
const NAV_SOON_PHRASES = ["奇蹟醞釀中", // 頁面準備中,呼應黃色奇蹟的誕生
"感動載入中", // 資料讀取中,連結入坑時的悸動
"初心校準中", // 結構調整中,呼應 LOGO 的六人設計核心
"黃海漫延中", // 視覺填充中,發想自黃色海洋填滿漆黑的過程
"傳奇編排中", // 內容整理中,記錄 1999 年榮譽與歷史軌跡
"夢想航行中", // 未來規劃中,期待水晶男孩的下一個十年
];
function pickSoonPhrase() {
return NAV_SOON_PHRASES[Math.floor(Math.random() * NAV_SOON_PHRASES.length)];
}
/** 每次互動重抽,讀者沿導覽滑動時會交錯看到不同字樣 */
function rollSoonLabel(link) {
const p = pickSoonPhrase();
link.style.setProperty("--portal-nav-soon-msg", JSON.stringify(p));
link.setAttribute("title", p);
}
const COMING_SOON_PAGES = new Set([
"variety.html",
"concert.html",
"albums.html",
"map.html",
"minister.html",
"minister_ge.html",
]);
/** 目前先開:淪陷瞬間 #origin + 子選單三項 #start / #mission / #timeline */
const INDEX_NAV_OPEN_HASHES = new Set(["#origin", "#start", "#mission", "#timeline"]);
function normalizePageKey(href) {
if (!href || href === "#") return "";
const core = href.split("#")[0].split("?")[0];
const parts = core.split("/").filter(Boolean);
const last = parts.length ? parts[parts.length - 1] : "";
return last.toLowerCase();
}
/** 比照原邏輯:取 href 前半與網址列檔名比對 */
function hrefMatchesCurrentPage(href, currentPage) {
if (!href || href === "#") return false;
const [filePart] = href.split("#");
const base = filePart.split("/").pop();
return base === currentPage;
}
/** 取得 #fragment(含 #);若無錨點則回傳空字串 */
function anchorFromHref(href) {
const i = href.indexOf("#");
if (i < 0) return "";
return href.slice(i).split("?")[0];
}
function markLinkComingSoon(link, originalHref) {
const visibleTitle = link.textContent.trim();
link.setAttribute("data-coming-soon", "true");
link.setAttribute("aria-disabled", "true");
link.setAttribute("aria-label", `${visibleTitle},尚無開放`);
const onSoonInteract = () => rollSoonLabel(link);
link.addEventListener("pointerenter", onSoonInteract);
link.addEventListener("focus", onSoonInteract);
link.addEventListener("touchstart", onSoonInteract, { passive: true });
if (!link.dataset.originalHref) {
link.dataset.originalHref = originalHref;
}
link.setAttribute("href", "#");
}
function linkShouldBeComingSoon(href, pageKey, pageKeysSoon) {
if (pageKeysSoon.has(pageKey)) {
return true;
}
if (pageKey === "index.html") {
const frag = anchorFromHref(href);
return !INDEX_NAV_OPEN_HASHES.has(frag);
}
return false;
}
/** 將籌備中規則套用至單一導覽列 */
function applyComingSoonToNav(nav) {
const pageKeysSoon = new Set(
[...COMING_SOON_PAGES].map((p) => normalizePageKey(String(p))).filter(Boolean),
);
nav.querySelectorAll('a[href]').forEach((link) => {
if (link.classList.contains("logo")) return;
const href = link.getAttribute("href");
if (!href || href === "#") return;
const pageKey = normalizePageKey(href);
if (!pageKey) return;
if (!linkShouldBeComingSoon(href, pageKey, pageKeysSoon)) return;
markLinkComingSoon(link, href);
});
nav.querySelectorAll(":scope > ul > li").forEach((li) => {
const trigger = li.querySelector(":scope > a[href]");
if (!trigger || trigger.classList.contains("logo")) return;
if (trigger.getAttribute("data-coming-soon") === "true") {
li.classList.add("coming-soon");
}
});
}
/**
* 站根與 `portal-nav.js` 同層;依腳本路徑與當前頁路徑計算回到站根的相對前綴(如 `../`)。
* 子資料夾內頁面之導覽連結必須帶此前綴,否則 `./images`、`index.html` 會錯層。
*/
function portalNavRootPrefix() {
const el =
document.currentScript ||
Array.from(document.querySelectorAll("script[src*='portal-nav.js']")).find((s) => s.src);
if (!el?.src) return "./";
try {
const scriptPathname = new URL(el.src, window.location.href).pathname;
const scriptDirSegs = scriptPathname.split("/").filter(Boolean);
scriptDirSegs.pop();
const pageDirSegs = window.location.pathname.split("/").filter(Boolean);
pageDirSegs.pop();
let i = 0;
const a = scriptDirSegs;
const b = pageDirSegs;
while (i < a.length && i < b.length && a[i] === b[i]) {
i += 1;
}
const ups = b.length - i;
return ups > 0 ? "../".repeat(ups) : "./";
} catch {
return "./";
}
}
/** 全站導覽 HTML — `rp` 為站根相對前綴;僅修改此模板即可同步所有頁面 */
function buildPortalNavInnerHTML(rp) {
return `