Files
Sansheng-Intelligence/public/assets/js/app.js
T
Jack 7e74bd989e fix: 对齐平台渠道与最新情报快照
2026-08-14 平台渠道专项更新:前端和静态SEO只展示平台官网、官方入驻及非中文入驻页辅助翻译;移除类目入口翻译、消费者官网翻译和内部成熟度/新兴参考分文案。

同步59/59权威源、65场跨境活动、28个平台和208条趋势内容;修正IBTE、CCBEC、法国教育部、Shopee和Shopify语种判断,更新README与CHANGELOG并通过Python、Node及静态构建验证。
2026-08-14 22:18:51 +08:00

59 lines
2.5 KiB
JavaScript

import { getIntelligenceSection, renderIntelligence, setIntelligenceSection, shareIntelligence } from "./render-intelligence.js?v=20260814o";
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 = `<div class="intelligence-empty">${error.message}。请先运行 update.bat。</div>`;
}
}
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();
});