import { getIntelligenceSection, renderIntelligence, setIntelligenceSection, shareIntelligence } from "./render-intelligence.js?v=20260817a"; const DATA_ROOT = "./data"; async function json(name) { const response = await fetch(`${DATA_ROOT}/${name}?t=${Date.now()}`, { cache: "no-store" }); if (!response.ok) throw new Error(`${name} 加载失败:HTTP ${response.status}`); return response.json(); } function showToast(message) { const toast = document.getElementById("toast"); toast.textContent = message; toast.classList.add("visible"); window.setTimeout(() => toast.classList.remove("visible"), 2200); } function applyTheme(theme) { document.documentElement.dataset.theme = theme; localStorage.setItem("sansheng-intelligence-theme", theme); const button = document.getElementById("themeBtn"); const label = theme === "dark" ? "切换到亮色主题" : "切换到暗色主题"; button?.setAttribute("aria-label", label); if (button) button.title = label; document.querySelector('meta[name="theme-color"]')?.setAttribute("content", theme === "dark" ? "#091119" : "#f5f8fb"); } function syncUrl(value) { const url = new URL(window.location.href); url.searchParams.set("intel", value || getIntelligenceSection()); history.replaceState(null, "", url); } async function init() { try { const params = new URLSearchParams(window.location.search); setIntelligenceSection(params.get("intel") || "today"); applyTheme(localStorage.getItem("sansheng-intelligence-theme") || "light"); const [intelligence, trends] = await Promise.all([json("textile-intelligence.json"), json("textile-trends.json")]); renderIntelligence({ ...intelligence, trends }, { root: document.getElementById("intelligencePanel"), onStateChange: syncUrl, }); syncUrl(getIntelligenceSection()); } catch (error) { console.error("[三笙AI情报局] 初始化失败:", error); document.getElementById("intelligenceList").innerHTML = `
${error.message}。请先运行 update.bat。
`; } } document.addEventListener("DOMContentLoaded", () => { document.getElementById("themeBtn").addEventListener("click", () => applyTheme(document.documentElement.dataset.theme === "dark" ? "light" : "dark")); document.getElementById("shareBtn").addEventListener("click", async () => { try { showToast(await shareIntelligence()); } catch (error) { console.error("[三笙AI情报局] 分享失败:", error); showToast("分享失败,请复制地址栏链接"); } }); init(); });