(function(){const i=document.createElement("link").relList;if(i&&i.supports&&i.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))l(t);new MutationObserver(t=>{for(const n of t)if(n.type==="childList")for(const r of n.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&l(r)}).observe(document,{childList:!0,subtree:!0});function v(t){const n={};return t.integrity&&(n.integrity=t.integrity),t.referrerPolicy&&(n.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?n.credentials="include":t.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function l(t){if(t.ep)return;t.ep=!0;const n=v(t);fetch(t.href,n)}})();const s=document.querySelector("#serve-button"),y=document.querySelector("#port-value"),p=document.querySelector("#status-hero"),x=document.querySelector("#status-ring"),C=document.querySelector("#status-dot"),S=document.querySelector("#status-label"),h=document.querySelector("#status-sub"),w=document.querySelector("#btn-icon"),E=document.querySelector("#btn-text"),q=document.querySelector("#version-badge"),a=document.querySelector("#diag-daemon"),f=document.querySelector("#diag-daemon-icon"),c=document.querySelector("#diag-ext"),g=document.querySelector("#diag-ext-icon"),N=document.querySelector("#trouble-hint");let o=null,b=null;function m(e){o=e;const i=e.connectionState==="connected",v=e.connectionState==="error",l=e.connectionState==="waiting"||e.connectionState==="connecting";q&&(q.textContent="v"+chrome.runtime.getManifest().version),y&&(y.textContent=String(e.port),y.className="diag-value");const t=e.activeCommands??0;let n="",r="",d="已停止",u="点击下方按钮启动服务";t>0&&i?(n="ring-active",r="dot-active",d="正在控制浏览器",u=`${t} 个命令执行中…`):i?(n="ring-on",r="dot-on",d="已连接",u=`端口 ${e.port} · 等待指令`):l?(n="ring-wait",r="dot-wait",d="连接中…",u=`扫描端口 ${e.port}`):e.servingEnabled&&v?(n="",r="",d="出错了",u=e.statusText||"未知错误"):e.servingEnabled&&(n="ring-wait",r="dot-wait",d="等待 daemon",u="请先启动 daemon"),p&&(p.className=`status-hero ${t>0?"is-active":""}`),x&&(x.className=`status-ring ${n}`),C&&(C.className=`status-dot ${r}`),S&&(S.textContent=d),h&&(h.textContent=u),s&&s.classList.toggle("is-off",!e.servingEnabled),w&&(w.innerHTML=e.servingEnabled?"■":"▶"),E&&(E.textContent=e.servingEnabled?"停止服务":"启动服务"),a&&f&&(i?(a.textContent=`运行中 :${e.port}`,a.className="diag-value ok",f.textContent="✅"):l?(a.textContent="检测中…",a.className="diag-value warn",f.textContent="🔍"):(a.textContent="未检测到",a.className="diag-value error",f.textContent="❌")),c&&g&&(i?(c.textContent="Serving 已开启",c.className="diag-value ok",g.textContent="✅"):e.servingEnabled?(c.textContent="等待 daemon",c.className="diag-value warn",g.textContent="⏳"):(c.textContent="未启动 Serving",c.className="diag-value error",g.textContent="⏹️")),N&&(N.hidden=!(e.servingEnabled&&!i&&!l))}async function P(e){return await chrome.runtime.sendMessage(e)}async function L(){try{m(await P({type:"chrisgao:get-popup-state"}))}catch(e){m({servingEnabled:!1,port:(o==null?void 0:o.port)??12190,statusText:e instanceof Error?e.message:"加载失败",connectionState:"error",defaultPortBusy:!1})}}async function $(){if(s){s.disabled=!0;try{const e=await P({type:"chrisgao:set-serving",enabled:!(o!=null&&o.servingEnabled)});m(e)}catch{m({servingEnabled:!!(o!=null&&o.servingEnabled),port:(o==null?void 0:o.port)??12190,statusText:"操作失败",connectionState:"error",defaultPortBusy:!1})}finally{s.disabled=!1}}}async function I(){s==null||s.addEventListener("click",()=>{$()}),await L(),b=window.setInterval(()=>{L()},1500)}window.addEventListener("beforeunload",()=>{b!==null&&window.clearInterval(b)});I();
