const errorEl = document.getElementById("aurora-error"); function showError(message: string) { if (!errorEl) return; errorEl.style.display = "block"; errorEl.textContent = message; } function loadScript(src: string): Promise { return new Promise((resolve, reject) => { const script = document.createElement("script"); script.src = src; script.async = true; script.onload = () => resolve(); script.onerror = () => reject(new Error(`无法加载 ${src}`)); document.head.appendChild(script); }); } async function boot() { const origin = window.location.origin; try { await loadScript(`${origin}/embed/aurora.js?v=1`); } catch { showError( `无法加载前台脚本:${origin}/embed/aurora.js。请确认 B 站已反代到 A 站,且 A 站已部署 embed 产物。` ); return; } const api = window.AuroraSite; if (!api?.mount) { showError("脚本已加载,但未找到 AuroraSite.mount。"); return; } api.mount("#aurora-root", { assetBase: origin, apiBase: origin, cssUrl: `${origin}/embed/aurora.css?v=1`, history: "hash", }); } boot(); declare global { interface Window { AuroraSite?: { mount: ( target: string | Element, options?: { assetBase?: string; apiBase?: string; cssUrl?: string; history?: "hash" | "browser"; basename?: string; } ) => { unmount: () => void }; }; } }