"use strict";(()=>{function o(t,n){chrome.runtime.sendMessage({type:"ANALYTICS",event:t,properties:n??{}}).catch(()=>{})}var s=t=>document.getElementById(t),O=s("site-domain"),p=s("action-btn"),_=s("action-text"),S=s("site-toggle"),x=s("content"),E=s("assist-control"),P=s("assist-pill"),B=s("assist-hint"),k=s("seg-control"),D=s("seg-pill"),M=s("preview"),h=s("vocab-select"),G=s("link-options"),w=s("pause-btn"),y=s("disabled-page"),N={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"},R={1:{chunkGranularity:"coarse",scanThreshold:"long",sensitivity:5},2:{chunkGranularity:"medium",scanThreshold:"medium",sensitivity:3},3:{chunkGranularity:"fine",scanThreshold:"short",sensitivity:1}},H={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 U(t){let n=t.sensitivity;return n>=5?1:n>=3?2:3}function q(t){return t>=4?"structure":t>=2?"lines":"light"}function F(t,n,b){let m=t.querySelectorAll(".seg-btn"),d=0;m.forEach((e,a)=>{let i=e===b;e.classList.toggle("active",i),i&&(d=a)}),n.style.transform=`translateX(${d*100}%)`}function A(t,n,b,m){let d=t.querySelector(`.seg-btn[data-${b}="${m}"]`);d&&F(t,n,d)}var r=null,g="",c=!1,u=!0;function l(t){return chrome.runtime.sendMessage(t)}function v(t){document.body.classList.toggle("global-off",!t);let n=t?"\u6682\u505C\u63B0it":"\u542F\u52A8\u63B0it";w.title=n,w.setAttribute("aria-label",n)}function L(){c?(p.className="action-btn is-on",_.textContent="\u663E\u793A\u539F\u6587"):(p.className="action-btn is-off",_.textContent="\u63B0it"),u?(p.style.opacity="1",p.style.pointerEvents="auto"):(p.style.opacity="0.4",p.style.pointerEvents="none")}function T(){x.classList.toggle("disabled",!u)}function C(t){A(E,P,"level",String(t)),B.textContent=N[t]||""}function I(t){let n=H[t];n&&(A(k,D,"mode",t),M.className="display-preview mode-"+t,M.innerHTML=n.html)}async function Y(){let[t]=await chrome.tabs.query({active:!0,currentWindow:!0});if(r=t??null,r?.url)try{g=new URL(r.url).hostname}catch{g=""}if(O.textContent=g||"\u2014",r?.id&&g){let e=await l({type:"getTabState",tabId:r.id,hostname:g});u=e.state!=="disabled",c=e.state==="active"}let n=await l({type:"getConfig"});S.checked=u;let b=U(n);C(b);let m=await chrome.storage.sync.get({vocabLevel:"all",globalEnabled:!0});h.value=m.vocabLevel,v(m.globalEnabled);let d=q(n.chunkIntensity);I(d),L(),T(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{E.classList.remove("no-transition"),k.classList.remove("no-transition")})}),o("popup_opened"),p.addEventListener("click",async()=>{!u||!r?.id||(c=!c,o("popup_action_btn_clicked",{state:c?"on":"off"}),c?await l({type:"resumeTab",tabId:r.id}):await l({type:"pauseTab",tabId:r.id}),L(),T())}),S.addEventListener("change",async()=>{if(!g)return;u=(await l({type:"toggleSite",hostname:g})).enabled,o("popup_site_toggle_changed",{enabled:u}),u?c=!0:c=!1,L(),T()}),E.addEventListener("click",async e=>{let a=e.target.closest(".seg-btn");if(!a||a.classList.contains("active"))return;let i=Number(a.dataset.level);o("popup_assist_level_changed",{level:i}),C(i);let f=R[i];await l({type:"updateConfig",config:f})}),k.addEventListener("click",async e=>{let a=e.target.closest(".seg-btn");if(!a||a.classList.contains("active"))return;let i=a.dataset.mode;o("popup_display_mode_changed",{mode:i}),I(i);let f=H[i];await l({type:"updateConfig",config:{chunkIntensity:f.intensity}})}),h.addEventListener("change",async()=>{o("popup_vocab_level_changed",{level:h.value}),await chrome.storage.sync.set({vocabLevel:h.value})}),G.addEventListener("click",e=>{o("popup_options_link_clicked"),e.preventDefault(),chrome.runtime.openOptionsPage()}),w.addEventListener("click",async()=>{let e=await l({type:"toggleGlobal"});v(e.globalEnabled),o("popup_global_toggle_changed",{enabled:e.globalEnabled})}),y.addEventListener("click",async()=>{let e=await l({type:"toggleGlobal"});v(e.globalEnabled),o("popup_global_toggle_changed",{enabled:e.globalEnabled,via:"startup_page"})}),y.addEventListener("keydown",e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),y.click())}),chrome.storage.onChanged.addListener((e,a)=>{a==="sync"&&e.globalEnabled&&v(e.globalEnabled.newValue)})}Y();})();
