"use strict";(()=>{function o(t,e){chrome.runtime.sendMessage({type:"ANALYTICS",event:t,properties:e??{}}).catch(()=>{})}var n=t=>document.getElementById(t),H=n("site-name"),A=n("site-domain"),p=n("action-btn"),E=n("action-text"),k=n("site-toggle"),C=n("content"),T=n("assist-control"),x=n("assist-pill"),O=n("assist-hint"),L=n("seg-control"),P=n("seg-pill"),w=n("preview"),f=n("vocab-select"),N=n("link-options"),B={1:"\u53EA\u63B0\u957F\u96BE\u53E5\uFF0C\u7B80\u5355\u53E5\u4E0D\u52A8",2:"\u8BE5\u63B0\u5C31\u63B0\uFF0C\u7B80\u5355\u53E5\u4E0D\u6253\u6270",3:"\u5C3D\u91CF\u90FD\u63B0\u5F00"},D={1:{chunkGranularity:"coarse",scanThreshold:"long",sensitivity:5},2:{chunkGranularity:"medium",scanThreshold:"medium",sensitivity:3},3:{chunkGranularity:"fine",scanThreshold:"short",sensitivity:1}},M={structure:{intensity:5,html:`
      <span class="line line-main">She finished the project</span>
      <span class="line line-sub1">that no one thought was possible,</span>
      <span class="line line-sub2">before the deadline.</span>
    `},lines:{intensity:3,html:`
      <span class="line">She finished the project</span>
      <span class="line">that no one thought was possible,</span>
      <span class="line">before the deadline.</span>
    `},light:{intensity:1,html:'<span class="line line-main">She finished the project</span><span class="dot"> \xB7 </span><span class="line line-sub">that no one thought was possible,</span><span class="dot"> \xB7 </span><span class="line line-sub">before the deadline.</span>'}};function R(t){let e=t.sensitivity;return e>=5?1:e>=3?2:3}function G(t){return t>=4?"structure":t>=2?"lines":"light"}function q(t,e,g){let h=t.querySelectorAll(".seg-btn"),d=0;h.forEach((s,a)=>{let i=s===g;s.classList.toggle("active",i),i&&(d=a)}),e.style.transform=`translateX(${d*100}%)`}function I(t,e,g,h){let d=t.querySelector(`.seg-btn[data-${g}="${h}"]`);d&&q(t,e,d)}var c=null,l="",r=!1,u=!0;function m(t){return chrome.runtime.sendMessage(t)}function b(){r?(p.className="action-btn is-on",E.textContent="\u663E\u793A\u539F\u6587"):(p.className="action-btn is-off",E.textContent="\u63B0it"),u?(p.style.opacity="1",p.style.pointerEvents="auto"):(p.style.opacity="0.4",p.style.pointerEvents="none")}function y(){C.classList.toggle("disabled",!u)}function S(t){I(T,x,"level",String(t)),O.textContent=B[t]||""}function _(t){let e=M[t];e&&(I(L,P,"mode",t),w.className="display-preview mode-"+t,w.innerHTML=e.html)}async function U(){let[t]=await chrome.tabs.query({active:!0,currentWindow:!0});if(c=t??null,c?.url)try{l=new URL(c.url).hostname}catch{l=""}if(H.textContent=l||"\u2014",A.textContent=l||"\u2014",c?.id&&l){let s=await m({type:"getTabState",tabId:c.id,hostname:l});u=s.state!=="disabled",r=s.state==="active"}let e=await m({type:"getConfig"});k.checked=u;let g=R(e);S(g);let h=await chrome.storage.sync.get({vocabLevel:"all"});f.value=h.vocabLevel;let d=G(e.chunkIntensity);_(d),b(),y(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{T.classList.remove("no-transition"),L.classList.remove("no-transition")})}),o("popup_opened"),p.addEventListener("click",async()=>{!u||!c?.id||(r=!r,o("popup_action_btn_clicked",{state:r?"on":"off"}),r?await m({type:"resumeTab",tabId:c.id}):await m({type:"pauseTab",tabId:c.id}),b(),y())}),k.addEventListener("change",async()=>{if(!l)return;u=(await m({type:"toggleSite",hostname:l})).enabled,o("popup_site_toggle_changed",{enabled:u}),u?r=!0:r=!1,b(),y()}),T.addEventListener("click",async s=>{let a=s.target.closest(".seg-btn");if(!a||a.classList.contains("active"))return;let i=Number(a.dataset.level);o("popup_assist_level_changed",{level:i}),S(i);let v=D[i];await m({type:"updateConfig",config:v})}),L.addEventListener("click",async s=>{let a=s.target.closest(".seg-btn");if(!a||a.classList.contains("active"))return;let i=a.dataset.mode;o("popup_display_mode_changed",{mode:i}),_(i);let v=M[i];await m({type:"updateConfig",config:{chunkIntensity:v.intensity}})}),f.addEventListener("change",async()=>{o("popup_vocab_level_changed",{level:f.value}),await chrome.storage.sync.set({vocabLevel:f.value})}),N.addEventListener("click",s=>{o("popup_options_link_clicked"),s.preventDefault(),chrome.runtime.openOptionsPage()})}U();})();
