var P={gemini:{apiKey:"",model:"gemini-3.1-flash-lite-preview"},chatgpt:{apiKey:"",model:"gpt-4.1-mini"},deepseek:{apiKey:"",model:"deepseek-chat"},qwen:{apiKey:"",model:"qwen3-flash"},kimi:{apiKey:"",model:"kimi-k2.5"}},B={llm:{activeProvider:"gemini",providers:{...P}},sensitivity:3,scanThreshold:"medium",chunkGranularity:"fine",chunkIntensity:5,disabledSites:[]},ee={gemini:{format:"gemini",baseUrl:"",label:"Gemini"},chatgpt:{format:"openai-compatible",baseUrl:"https://api.openai.com",label:"ChatGPT"},deepseek:{format:"openai-compatible",baseUrl:"https://api.deepseek.com",label:"DeepSeek"},qwen:{format:"openai-compatible",baseUrl:"https://dashscope.aliyuncs.com/compatible-mode",label:"Qwen"},kimi:{format:"openai-compatible",baseUrl:"https://api.moonshot.cn",label:"Kimi"}};function R(e){let n=e.activeProvider,t=e.providers[n],r=ee[n];return{format:r.format,apiKey:t.apiKey,baseUrl:r.baseUrl,model:t.model}}function S(e){if(e&&typeof e=="object"&&"activeProvider"in e)return e;let n=e,t={...P};if(n?.apiKey){let r=n.format==="gemini"?"gemini":"chatgpt";return t[r]={apiKey:n.apiKey,model:n.model||P[r].model},{activeProvider:r,providers:t}}return{activeProvider:"gemini",providers:t}}var C=10080*60*1e3;var te="openen-cache",ne=1,m="chunks";function A(){return new Promise((e,n)=>{let t=indexedDB.open(te,ne);t.onupgradeneeded=()=>{let r=t.result;r.objectStoreNames.contains(m)||r.createObjectStore(m,{keyPath:"hash"})},t.onsuccess=()=>e(t.result),t.onerror=()=>n(t.error)})}function T(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=n*16777619>>>0;return n.toString(36)}async function O(e){let n=new Map;try{let a=(await A()).transaction(m,"readonly").objectStore(m);await Promise.all(e.map(s=>new Promise(o=>{let c=T(s),i=a.get(c);i.onsuccess=()=>{let u=i.result;u&&Date.now()-u.timestamp<=C&&n.set(s,u.result),o()},i.onerror=()=>o()})))}catch{}return n}async function L(e){try{let r=(await A()).transaction(m,"readwrite").objectStore(m);for(let{sentence:a,result:s}of e){let o=T(a);r.put({hash:o,result:s,timestamp:Date.now()})}}catch{}}function re(e,n=[]){return`You are an English reading assistant. Your job is to restructure complex English sentences into indented chunks that reveal their grammatical structure, making them easier to parse visually.

## Rules

1. **Skeleton first**: The main clause (subject-verb-object) stays at the top level (no indentation).
2. **Indent subordinate elements**: Each level of nesting gets 2 more spaces of indentation:
   - Subordinate clauses (that, which, who, if, because, although, etc.)
   - Relative clauses
   - Conditional clauses
   - Temporal clauses
   - Participial phrases, prepositional phrases, and appositive phrases
3. **Simple sentences**: If a sentence has no subordinate clauses and is straightforward, return it unchanged with is_simple=true.
4. **Preserve original text**: Do not change any words. Only add line breaks and indentation. Do NOT add brackets, parentheses, or any other symbols that are not in the original text.

## New Words

${n.length>0?`The user already knows these words (do NOT mark them as new): ${n.join(", ")}`:"The user is at an advanced English level (IELTS 7+). Be very selective \u2014 only mark words that a proficient non-native reader would genuinely not know."}

For each sentence, identify words that the user likely doesn't know. Provide a brief Chinese definition for each.

Important constraints for new_words:
- Do NOT mark proper nouns, brand names, or product names (e.g. ChatGPT, Google, Tesla, iPhone)
- Do NOT mark common tech/internet terms (e.g. AI, API, app, blog, email, online)
- Do NOT mark words that appear in any standard 6000-word English vocabulary list
- Only mark words that would genuinely challenge an advanced reader \u2014 rare, literary, domain-specific, or highly idiomatic expressions
- When in doubt, do NOT mark it. Fewer is better.

## Input

${e.map((r,a)=>`[${a}] ${r}`).join(`
`)}

## Output Format

Return a JSON array with one object per input sentence, in the same order:

\`\`\`json
[
  {
    "index": 0,
    "original": "the original sentence",
    "chunked": "the chunked version with\\n  indentation\\n    and nested clauses",
    "is_simple": false,
    "new_words": [
      {"word": "example", "definition": "\u4F8B\u5B50\uFF0C\u5B9E\u4F8B"}
    ]
  }
]
\`\`\`

Important:
- Use \\n for line breaks in the chunked field
- Use spaces (not tabs) for indentation, 2 spaces per level
- Return valid JSON only, no markdown fences
- The array must have exactly ${e.length} elements`}var ae="https://generativelanguage.googleapis.com/v1beta/models";function E(e,n){let t=n.model||"gemini-2.0-flash";return{url:`${ae}/${t}:generateContent?key=${n.apiKey}`,body:{contents:[{parts:[{text:e}]}],generationConfig:{temperature:.1,responseMimeType:"application/json",thinkingConfig:{thinkingBudget:0}}}}}function j(e,n){let r=`${n.baseUrl.replace(/\/+$/,"")}/v1/chat/completions`,a={model:n.model,messages:[{role:"system",content:"You are a helpful English reading assistant. Always respond with valid JSON."},{role:"user",content:e}],temperature:.1,response_format:{type:"json_object"}},s={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};return{url:r,body:a,headers:s}}function se(e){let t=e?.candidates?.[0]?.content?.parts?.[0]?.text;if(!t)throw new Error("Gemini \u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");return K(t)}function oe(e){let t=e?.choices?.[0]?.message?.content;if(!t)throw new Error("OpenAI \u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");return K(t)}function K(e){let n=e.trim(),t=n.match(/```(?:json)?\s*([\s\S]*?)```/);t&&(n=t[1].trim());let r;try{r=JSON.parse(n)}catch{throw new Error(`LLM \u8FD4\u56DE\u7684 JSON \u683C\u5F0F\u65E0\u6548: ${n.slice(0,100)}...`)}if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,s=Object.keys(a).find(o=>Array.isArray(a[o]));s&&(r=a[s])}if(!Array.isArray(r))throw new Error("LLM \u8FD4\u56DE\u7684\u4E0D\u662F\u6570\u7EC4\u683C\u5F0F");return r.map(a=>({index:a.index??0,original:a.original??"",chunked:a.chunked??a.original??"",is_simple:a.is_simple??!0,new_words:Array.isArray(a.new_words)?a.new_words:[]}))}function M(e,n){return e.map((t,r)=>{let a=n.find(s=>s.index===r);return a?{original:a.original||t,chunked:a.chunked,isSimple:a.is_simple,newWords:a.new_words??[]}:{original:t,chunked:t,isSimple:!0,newWords:[]}})}async function N(e,n,t=[]){let r=re(e,t),a;if(n.format==="gemini"){let{url:s,body:o}=E(r,n),c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!c.ok){let u=await c.text();throw new Error(`Gemini API \u9519\u8BEF (${c.status}): ${u.slice(0,200)}`)}a=await c.json();let i=se(a);return M(e,i)}else{let{url:s,body:o,headers:c}=j(r,n),i=await fetch(s,{method:"POST",headers:c,body:JSON.stringify(o)});if(!i.ok){let Z=await i.text();throw new Error(`OpenAI API \u9519\u8BEF (${i.status}): ${Z.slice(0,200)}`)}a=await i.json();let u=oe(a);return M(e,u)}}var V=["insertion","background_first","nested","long_list","inverted","long_subject","omission","contrast","condition","long_modifier","other"];function ie(e){return`You are an English reading assistant for Chinese learners. Analyze the following English sentence in depth.

## Input sentence

${e}

## Output format

Return a single JSON object (NOT an array) with these fields:

\`\`\`json
{
  "chunked": "the chunked version with\\n  indentation",
  "pattern_key": "one of the allowed keys",
  "sentence_analysis": "\u7528\u4E2D\u6587\u89E3\u91CA\u8FD9\u53E5\u8BDD\u4E3A\u4EC0\u4E48\u96BE\u8BFB\uFF0C\u6307\u51FA\u54EA\u4E9B\u7ED3\u6784\u9020\u6210\u4E86\u9605\u8BFB\u969C\u788D",
  "expression_tips": "\u7528\u4E2D\u6587\u8BB2\u89E3\u8FD9\u53E5\u8BDD\u4E2D\u503C\u5F97\u5B66\u4E60\u7684\u8868\u8FBE\u65B9\u5F0F\u548C\u53E5\u5F0F\uFF0C\u7528 **\u52A0\u7C97** \u6807\u6CE8\u5173\u952E\u8868\u8FBE",
  "new_words": [{"word": "example", "definition": "\u4F8B\u5B50\uFF0C\u5B9E\u4F8B"}],
  "is_worth_practicing": true
}
\`\`\`

## Rules

### chunked
- Main clause (subject-verb-object) at top level (no indentation)
- Indent subordinate elements with 2 spaces per level
- Preserve original text exactly, only add \\n and spaces

### pattern_key
Must be one of: ${V.join(", ")}

### sentence_analysis & expression_tips
- Write in Chinese (\u4E2D\u6587)
- Be concise but insightful

### new_words
- Only words that a IELTS 7+ Chinese reader might not know
- Do NOT mark proper nouns, brand names, common tech terms
- Provide brief Chinese definitions

### is_worth_practicing
- true if the sentence has interesting structure worth studying
- false if it's straightforward despite being long

Return valid JSON only, no markdown fences.`}function ce(e){let n=e.trim(),t=n.match(/```(?:json)?\s*([\s\S]*?)```/);t&&(n=t[1].trim());let r;try{r=JSON.parse(n)}catch{throw new Error(`LLM \u8FD4\u56DE\u7684 JSON \u683C\u5F0F\u65E0\u6548: ${n.slice(0,100)}...`)}let a=r,s=String(a.pattern_key||"other");return V.includes(s)||(s="other"),{chunked:String(a.chunked||""),pattern_key:s,sentence_analysis:String(a.sentence_analysis||""),expression_tips:String(a.expression_tips||""),new_words:Array.isArray(a.new_words)?a.new_words.map(o=>({word:String(o.word||""),definition:String(o.definition||"")})):[],is_worth_practicing:!!a.is_worth_practicing}}function de(e,n){if(n==="gemini"){let r=e?.candidates?.[0]?.content?.parts?.[0]?.text;if(!r)throw new Error("Gemini \u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");return r}else{let r=e?.choices?.[0]?.message?.content;if(!r)throw new Error("OpenAI \u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");return r}}async function W(e,n){let t=ie(e),r;if(n.format==="gemini"){let{url:s,body:o}=E(t,n),c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!c.ok){let i=await c.text();throw new Error(`Gemini API \u9519\u8BEF (${c.status}): ${i.slice(0,200)}`)}r=await c.json()}else{let{url:s,body:o,headers:c}=j(t,n),i=await fetch(s,{method:"POST",headers:c,body:JSON.stringify(o)});if(!i.ok){let u=await i.text();throw new Error(`OpenAI API \u9519\u8BEF (${i.status}): ${u.slice(0,200)}`)}r=await i.json()}let a=de(r,n.format);return ce(a)}var ue="openen-data";var d={vocab:"vocab",vocab_contexts:"vocab_contexts",patterns:"patterns",pattern_examples:"pattern_examples",learning_records:"learning_records",settings:"settings",weekly_reports:"weekly_reports",review_items:"review_items",wallpaper_records:"wallpaper_records",pending_sentences:"pending_sentences"};function $(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}var y=null;function q(e=indexedDB){return y?Promise.resolve(y):new Promise((n,t)=>{let r=e.open(ue,2);r.onupgradeneeded=a=>{let s=r.result,o=a.oldVersion,c=r.transaction;le(s,o,c)},r.onsuccess=()=>{y=r.result,y.onclose=()=>{y=null},n(y)},r.onerror=()=>t(r.error)})}function le(e,n,t){n<1&&pe(e),n<2&&ge(e,t)}function pe(e){let n=e.createObjectStore(d.vocab,{keyPath:"id"});n.createIndex("by_word","word",{unique:!0}),n.createIndex("by_status","status"),n.createIndex("by_updated_at","updated_at");let t=e.createObjectStore(d.vocab_contexts,{keyPath:"id"});t.createIndex("by_vocab_id","vocab_id"),t.createIndex("by_updated_at","updated_at");let r=e.createObjectStore(d.patterns,{keyPath:"id"});r.createIndex("by_key","key",{unique:!0}),r.createIndex("by_updated_at","updated_at");let a=e.createObjectStore(d.pattern_examples,{keyPath:"id"});a.createIndex("by_pattern_id","pattern_id"),a.createIndex("by_updated_at","updated_at");let s=e.createObjectStore(d.learning_records,{keyPath:"id"});s.createIndex("by_created_at","created_at"),s.createIndex("by_pattern_key","pattern_key"),s.createIndex("by_source_url","source_url"),s.createIndex("by_updated_at","updated_at"),e.createObjectStore(d.settings,{keyPath:"key"}).createIndex("by_updated_at","updated_at");let c=e.createObjectStore(d.weekly_reports,{keyPath:"id"});c.createIndex("by_week_start","week_start",{unique:!0}),c.createIndex("by_updated_at","updated_at");let i=e.createObjectStore(d.review_items,{keyPath:"id"});i.createIndex("by_type","type"),i.createIndex("by_reference_id","reference_id"),i.createIndex("by_next_review_at","next_review_at"),i.createIndex("by_updated_at","updated_at");let u=e.createObjectStore(d.wallpaper_records,{keyPath:"id"});u.createIndex("by_created_at","created_at"),u.createIndex("by_updated_at","updated_at")}function ge(e,n){let t=e.createObjectStore(d.pending_sentences,{keyPath:"id"});t.createIndex("by_text","text",{unique:!0}),t.createIndex("by_analyzed","analyzed"),t.createIndex("by_created_at","created_at"),t.createIndex("by_source_hostname","source_hostname"),t.createIndex("by_manual","manual"),t.createIndex("by_updated_at","updated_at"),n.objectStore(d.learning_records).createIndex("by_sentence","sentence")}function _(e,n,t){return e.transaction(n,t).objectStore(n)}function h(e){return new Promise((n,t)=>{e.onsuccess=()=>n(e.result),e.onerror=()=>t(e.error)})}function G(e){return new Promise((n,t)=>{e.oncomplete=()=>n(),e.onerror=()=>t(e.error),e.onabort=()=>t(e.error)})}async function z(e,n,t){return h(_(e,n,"readonly").get(t))}async function U(e,n,t,r){let s=_(e,n,"readonly").index(t);return h(s.getAll(r))}async function F(e,n){return h(_(e,n,"readonly").getAll())}async function I(e,n,t){let r=e.transaction(n,"readwrite");r.objectStore(n).put(t),await G(r)}async function J(e,n,t){let r=e.transaction(n,"readwrite");r.objectStore(n).delete(t),await G(r)}async function H(e,n,t,r){let s=_(e,n,"readonly").index(t);return h(s.get(r))}var k={async add(e,n){let t=Date.now(),r={id:$(),created_at:t,updated_at:t,is_dirty:!0,...n};return await I(e,d.learning_records,r),r},async getById(e,n){return z(e,d.learning_records,n)},async getAll(e){return F(e,d.learning_records)},async getByPatternKey(e,n){return U(e,d.learning_records,"by_pattern_key",n)},async getBySourceUrl(e,n){return U(e,d.learning_records,"by_source_url",n)},async update(e,n,t){let r=await this.getById(e,n);if(!r)return;let a={...r,...t,id:n,updated_at:Date.now(),is_dirty:!0};return await I(e,d.learning_records,a),a},async delete(e,n){await J(e,d.learning_records,n)},async getBySentence(e,n){return H(e,d.learning_records,"by_sentence",n)},async getByDateRange(e,n,t){let a=_(e,d.learning_records,"readonly").index("by_created_at"),s=IDBKeyRange.bound(n,t);return h(a.getAll(s))}};var w={async add(e,n){if(await this.getByText(e,n.text))return null;let r=Date.now(),a={id:$(),analyzed:!1,created_at:r,updated_at:r,is_dirty:!0,...n};return await I(e,d.pending_sentences,a),a},async getById(e,n){return z(e,d.pending_sentences,n)},async getByText(e,n){return H(e,d.pending_sentences,"by_text",n)},async getAll(e){return F(e,d.pending_sentences)},async getUnanalyzed(e){return(await this.getAll(e)).filter(t=>!t.analyzed).sort((t,r)=>t.manual!==r.manual?t.manual?-1:1:r.created_at-t.created_at)},async getPage(e,n,t){let r=await this.getAll(e);r.sort((s,o)=>s.manual!==o.manual?s.manual?-1:1:o.created_at-s.created_at);let a=(n-1)*t;return{records:r.slice(a,a+t),total:r.length}},async markAnalyzed(e,n){let t=await this.getById(e,n);t&&await I(e,d.pending_sentences,{...t,analyzed:!0,updated_at:Date.now(),is_dirty:!0})},async delete(e,n){await J(e,d.pending_sentences,n)}};async function g(){let e=Object.keys(B),t=await chrome.storage.sync.get(e);return Array.isArray(t.disabledSites)||(t.disabledSites=[]),t.chunkGranularity||(t.chunkGranularity="fine"),t.llm=S(t.llm),t}async function me(e){let n=await g(),t={...n,...e};return e.llm&&(t.llm={...n.llm,...e.llm}),await chrome.storage.sync.set(t),t}function f(e){try{return new URL(e).hostname}catch{return""}}async function x(e){return!(await g()).disabledSites.includes(e)}async function ye(e){let n=await g(),t=n.disabledSites.indexOf(e),r;return t>=0?(n.disabledSites.splice(t,1),r=!0):(n.disabledSites.push(e),r=!1),await chrome.storage.sync.set({disabledSites:n.disabledSites}),{enabled:r,disabledSites:n.disabledSites}}async function p(e,n){let t=n?"-on":"";try{await chrome.action.setIcon({path:{16:`icons/icon16${t}.png`,48:`icons/icon48${t}.png`,128:`icons/icon128${t}.png`},tabId:e})}catch{}}async function D(e){return(await chrome.storage.session.get({pausedTabs:[]})).pausedTabs.includes(e)}async function Q(e){let t=(await chrome.storage.session.get({pausedTabs:[]})).pausedTabs;t.includes(e)||(t.push(e),await chrome.storage.session.set({pausedTabs:t}))}async function v(e){let t=(await chrome.storage.session.get({pausedTabs:[]})).pausedTabs.filter(r=>r!==e);await chrome.storage.session.set({pausedTabs:t})}chrome.tabs.onRemoved.addListener(async e=>{await v(e)});var l=null,be=50,_e=5;function he(e,n){return new Promise(t=>{l||(l={sentences:[],source_url:n,resolvers:new Map,timer:null}),l.sentences.push(e),l.resolvers.set(e,t),l.timer&&clearTimeout(l.timer),l.sentences.length>=_e?Y():l.timer=setTimeout(Y,be)})}async function Y(){if(!l||l.sentences.length===0)return;let e=l;l=null,e.timer&&clearTimeout(e.timer);try{let n=await g(),t=R(n.llm);if(!t.apiKey)throw new Error("API key \u672A\u914D\u7F6E");let r=await N(e.sentences,t),a=r.map((s,o)=>({sentence:e.sentences[o],result:s}));L(a).catch(()=>{});for(let s=0;s<r.length;s++){let o=e.resolvers.get(e.sentences[s]);o&&o(r[s])}we(r.filter(s=>!s.isSimple).length)}catch{for(let[n,t]of e.resolvers)t({original:n,chunked:n,isSimple:!0,newWords:[]})}}async function we(e){let n=new Date().toISOString().slice(0,10),t=await chrome.storage.local.get({statsDate:"",todayChunked:0});t.statsDate!==n?await chrome.storage.local.set({statsDate:n,todayChunked:e}):await chrome.storage.local.set({todayChunked:t.todayChunked+e})}var b=null;async function X(){return b||(b=await q(),b.onclose=()=>{b=null},b)}async function fe(e){let n=await X(),t=await g(),r=R(t.llm);if(r.apiKey)for(let a=0;a<e.length;a++){let s=e[a];try{let o=await w.getById(n,s);if(!o||o.analyzed)continue;let c=await k.getBySentence(n,o.text);if(c){await w.markAnalyzed(n,s),chrome.runtime.sendMessage({type:"sentenceAnalyzed",pendingId:s,learningRecord:c}).catch(()=>{});continue}let i=await W(o.text,r),u=await k.add(n,{sentence:o.text,chunked:i.chunked,sentence_analysis:i.sentence_analysis,expression_tips:i.expression_tips,pattern_key:i.pattern_key,new_words:i.new_words,source_url:o.source_url,llm_provider:t.llm.activeProvider});await w.markAnalyzed(n,s),chrome.runtime.sendMessage({type:"sentenceAnalyzed",pendingId:s,learningRecord:u}).catch(()=>{})}catch(o){chrome.runtime.sendMessage({type:"sentenceAnalysisFailed",pendingId:s,error:o instanceof Error?o.message:"Unknown error"}).catch(()=>{})}a<e.length-1&&await new Promise(o=>setTimeout(o,500))}}chrome.runtime.onMessage.addListener((e,n,t)=>(xe(e,n).then(r=>{try{t(r)}catch{}}),!0));async function xe(e,n){switch(e.type){case"chunk":{let{sentences:t,source_url:r}=e,a=await O(t),s=t.filter(i=>!a.has(i));if(s.length===0)return{results:t.map(i=>a.get(i))};let o=await Promise.all(s.map(i=>he(i,r))),c=new Map;return s.forEach((i,u)=>c.set(i,o[u])),{results:t.map(i=>a.get(i)??c.get(i))}}case"checkActive":{let t=n.tab?.id,r=n.tab?.url??"",a=f(r),o=(a?await x(a):!1)&&!(t&&await D(t));return t&&p(t,o),{active:o}}case"toggleSite":{let{hostname:t}=e,r=await ye(t),a=await chrome.tabs.query({});for(let s of a)s.id&&s.url&&f(s.url)===t&&(p(s.id,r.enabled),chrome.tabs.sendMessage(s.id,{type:r.enabled?"activate":"deactivate"}).catch(()=>{}));return{enabled:r.enabled,disabledSites:r.disabledSites}}case"pauseTab":{let{tabId:t}=e;return await Q(t),p(t,!1),chrome.tabs.sendMessage(t,{type:"pause"}).catch(()=>{}),{ok:!0}}case"resumeTab":{let{tabId:t}=e;return await v(t),p(t,!0),chrome.tabs.sendMessage(t,{type:"resume"}).catch(()=>{}),{ok:!0}}case"getTabState":{let{tabId:t,hostname:r}=e;return await D(t)?{state:"paused"}:(r?await x(r):!1)?{state:"active"}:{state:"disabled"}}case"hasApiKey":{let t=await g();return{hasKey:!!R(t.llm).apiKey}}case"getConfig":return g();case"updateConfig":return me(e.config);case"saveSentence":try{let t=await X();return{ok:!0,saved:await w.add(t,{text:e.text,source_url:e.source_url,source_hostname:e.source_hostname,manual:e.manual,new_words:e.new_words})!==null}}catch{return{ok:!0,saved:!1}}case"analyzeSentences":{let{sentenceIds:t}=e;return fe(t).catch(()=>{}),{ok:!0}}default:return{error:"Unknown message type"}}}chrome.tabs.onActivated.addListener(async e=>{try{let n=await chrome.tabs.get(e.tabId);if(n.url){let t=f(n.url),a=(t?await x(t):!1)&&!await D(e.tabId);p(e.tabId,a)}}catch{}});chrome.tabs.onUpdated.addListener(async(e,n,t)=>{if(n.status==="complete"&&t.url){let r=f(t.url),s=(r?await x(r):!1)&&!await D(e);p(e,s)}});chrome.commands.onCommand.addListener(async e=>{if(e!=="toggle-page")return;let[n]=await chrome.tabs.query({active:!0,currentWindow:!0});if(!n?.id||!n.url)return;let t=f(n.url);if(!(t?await x(t):!1))return;await D(n.id)?(await v(n.id),p(n.id,!0),chrome.tabs.sendMessage(n.id,{type:"resume"}).catch(()=>{})):(await Q(n.id),p(n.id,!1),chrome.tabs.sendMessage(n.id,{type:"pause"}).catch(()=>{}))});
