(() => { "use strict"; const qs = (selector, root = document) => root.querySelector(selector); const qsa = (selector, root = document) => Array.from(root.querySelectorAll(selector)); const clone = (value) => JSON.parse(JSON.stringify(value)); const MODULES = ["site", "navigation", "composer", "posts", "trends", "recommendations"]; const MODULE_META = { site: ["站点信息", "品牌、标题与当前账号"], navigation: ["导航", "主导航、移动导航与页脚"], composer: ["发布框", "占位语与字数限制"], posts: ["动态", "时间线内容与互动量"], trends: ["趋势", "右栏热门话题"], recommendations: ["推荐关注", "右栏推荐账号"] }; const ALLOWED_ICONS = new Set(["i-home", "i-search", "i-bell", "i-message", "i-users", "i-bookmark", "i-user", "i-more"]); const embeddedData = JSON.parse(qs("#xPageData").textContent); const initialData = clone(embeddedData); const fingerprint = (text) => { let hash = 2166136261; for (let index = 0; index < text.length; index += 1) { hash ^= text.charCodeAt(index); hash = Math.imul(hash, 16777619); } return (hash >>> 0).toString(36); }; const pageFingerprint = fingerprint(JSON.stringify(initialData)); const storageKey = "x-page-data-v1:" + pageFingerprint; const themeKey = "x-page-theme-v1:" + pageFingerprint; const readStorage = (key) => { try { return window.localStorage ? window.localStorage.getItem(key) : null; } catch (_error) { return null; } }; const writeStorage = (key, value) => { try { if (window.localStorage) window.localStorage.setItem(key, value); return true; } catch (_error) { return false; } }; const removeStorage = (key) => { try { if (window.localStorage) window.localStorage.removeItem(key); } catch (_error) { /* Sandboxed previews may intentionally deny storage. */ } }; const isCompleteData = (value) => Boolean(value && MODULES.every((name) => value[name] && typeof value[name] === "object")); const cachedData = readStorage(storageKey); let pageData = initialData; if (cachedData) { try { const parsed = JSON.parse(cachedData); if (isCompleteData(parsed)) pageData = parsed; } catch (_error) { pageData = initialData; } } const escapeHTML = (value) => String(value == null ? "" : value).replace(/[&<>'"]/g, (character) => ({ "&": "&", "<": "<", ">": ">", "'": "'", '"': """ })[character]); const safeHref = (value) => { const href = String(value || "#"); return /^(#|https?:\/\/)/i.test(href) ? escapeHTML(href) : "#"; }; const safeRemoteUrl = (value, kind = "link") => { const source = String(value || "").trim(); if (!source) return ""; const lowered = source.toLowerCase(); if (kind === "image" && lowered.startsWith("data:image/")) return source; if (kind === "video" && lowered.startsWith("data:video/")) return source; try { const url = new URL(source); return url.protocol === "http:" || url.protocol === "https:" ? url.href : ""; } catch (_error) { return ""; } }; const validateRemoteMediaTree = (value, path = "当前模块") => { if (Array.isArray(value)) return value.forEach((item, index) => validateRemoteMediaTree(item, path + "[" + index + "]")); if (!value || typeof value !== "object") return; const media = value.media; if (media && ["image", "video", "webpage"].includes(media.type)) { if ((media.type === "image" || media.type === "video") && !safeRemoteUrl(media.mediaUrl, media.type)) throw new Error(path + ".media.mediaUrl 无效"); if (media.type === "webpage" && !safeRemoteUrl(media.pageUrl)) throw new Error(path + ".media.pageUrl 无效"); if (media.posterUrl && !safeRemoteUrl(media.posterUrl, "image")) throw new Error(path + ".media.posterUrl 无效"); } Object.entries(value).forEach(([key, item]) => { if (key !== "media") validateRemoteMediaTree(item, path + "." + key); }); }; const safeColor = (value, fallback) => /^#[0-9a-f]{3,8}$/i.test(String(value || "")) ? value : fallback; const safeIcon = (value) => ALLOWED_ICONS.has(value) ? value : "i-more"; const icon = (id, className) => '