import{b as d,g as se}from"./settings-mco8QK8Y.js";import{i as N,n as ae}from"./downloadIntent-Dv31jC2S.js";import{n as M}from"./clipTypes-C_ha5Ash.js";function _(){const e=document.body||document.documentElement;if(!e)return[];const n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),t=[];let r=0,o=n.nextNode();for(;o;){const l=o,s=(l.nodeValue||"").length;s>0&&(t.push({node:l,start:r,end:r+s}),r+=s),o=n.nextNode()}return t}function G(e){return e.map(n=>n.node.nodeValue||"").join("")}function X(e){const n=document.body||document.documentElement;if(!n)return"";if(e===n)return"/body";const t=[];let r=e.nodeType===Node.TEXT_NODE?e.parentNode:e;for(;r&&r!==n&&r.nodeType===Node.ELEMENT_NODE;){const o=r,l=o.tagName.toLowerCase();let i=1,s=o.previousElementSibling;for(;s;)s.tagName.toLowerCase()===l&&(i+=1),s=s.previousElementSibling;t.unshift(`${l}[${i}]`),r=o.parentElement}return`/body/${t.join("/")}`}function Y(e){if(!e)return null;try{return document.evaluate(e,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch{return null}}function ce(e){const n=e.commonAncestorContainer,t=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return!(!t||t.closest("input, textarea, select, button, script, style")||t.closest('[contenteditable="true"]'))}function ue(e,n,t){const r=e.slice(Math.max(0,n-40),n).trim(),o=e.slice(t,Math.min(e.length,t+40)).trim();return{prefix:r,suffix:o}}function de(e,n){const t=e.startContainer,r=e.endContainer;if(t.nodeType!==Node.TEXT_NODE||r.nodeType!==Node.TEXT_NODE)return null;const o=n.find(i=>i.node===t),l=n.find(i=>i.node===r);return!o||!l?null:{start:o.start+e.startOffset,end:l.start+e.endOffset}}function Q(e,n){if(!Number.isFinite(e)||!Number.isFinite(n)||e>=n)return null;const t=_(),r=t.find(i=>e>=i.start&&en>i.start&&n<=i.end);if(!r||!o)return null;const l=document.createRange();return l.setStart(r.node,Math.max(0,Math.min(r.node.length,e-r.start))),l.setEnd(o.node,Math.max(0,Math.min(o.node.length,n-o.start))),l}function fe(e){if(!e.xpathStart||!e.xpathEnd)return null;const n=Y(e.xpathStart),t=Y(e.xpathEnd);if(!n||!t||n.nodeType!==Node.ELEMENT_NODE||t.nodeType!==Node.ELEMENT_NODE)return null;const r=s=>{const a=document.createTreeWalker(s,NodeFilter.SHOW_TEXT).nextNode();return a&&a.nodeType===Node.TEXT_NODE?a:null},o=r(n),l=r(t);if(!o||!l||o.nodeType!==Node.TEXT_NODE||l.nodeType!==Node.TEXT_NODE||!Number.isInteger(e.startOffset)||!Number.isInteger(e.endOffset))return null;const i=document.createRange();return i.setStart(o,Math.min((o.nodeValue||"").length,Math.max(0,e.startOffset||0))),i.setEnd(l,Math.min((l.nodeValue||"").length,Math.max(0,e.endOffset||0))),i}function pe(e){const n=String(e.exact||"");if(!n)return null;const t=_(),r=G(t);let o=r.indexOf(n);if(o<0)return null;const l=String(e.prefix||""),i=String(e.suffix||"");if(!l&&!i)return{start:o,end:o+n.length};for(;o>=0;){const s=r.slice(Math.max(0,o-l.length),o).trim(),p=r.slice(o+n.length,o+n.length+i.length).trim();if((!l||s===l)&&(!i||p===i))return{start:o,end:o+n.length};o=r.indexOf(n,o+n.length)}return null}function ye(e){if(!e.rangeCount)return null;const n=e.getRangeAt(0);if(n.collapsed||!ce(n))return null;const t=e.toString();if(!t.trim())return null;const r=_(),o=de(n,r),l={exact:t};if(n.startContainer.nodeType===Node.TEXT_NODE&&n.endContainer.nodeType===Node.TEXT_NODE){const i=n.startContainer,s=n.endContainer;l.xpathStart=X(i),l.xpathEnd=X(s),l.startOffset=n.startOffset,l.endOffset=n.endOffset}if(o){l.startTextOffset=o.start,l.endTextOffset=o.end;const i=G(r),s=ue(i,o.start,o.end);s.prefix&&(l.prefix=s.prefix),s.suffix&&(l.suffix=s.suffix)}return{anchor:l,quote:t}}function me(e){if(Number.isInteger(e.startTextOffset)&&Number.isInteger(e.endTextOffset)){const r=Q(e.startTextOffset||0,e.endTextOffset||0);if(r&&!r.collapsed)return r}const n=pe(e);if(n){const r=Q(n.start,n.end);if(r&&!r.collapsed)return r}const t=fe(e);return t&&!t.collapsed?t:null}const he=8e3,k=new Map;let c=!1,V=null,I=M(window.location.href),U=0;function m(...e){console.log("[gomdown-helper][clip][content]",...e)}function ge(){const e=Date.now();for(const[n,t]of k.entries())t<=e&&k.delete(n)}async function v(e,n){if(!c)return!1;const t=ae(e,window.location.href);if(!t)return!1;if(ge(),k.has(t))return!0;k.set(t,Date.now()+he);try{if((await d.runtime.sendMessage({type:"capture-link-download",url:t,referer:n||document.referrer||window.location.href}))?.ok)return!0}catch{}return k.delete(t),!1}function q(e){return e?e instanceof HTMLAnchorElement?e:e instanceof Element?e.closest("a[href]"):null:null}function W(e){return!!(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)}function we(e){if(!e)return!1;const n=e instanceof Element?e:e instanceof Node?e.parentElement:null;return n?!!(n.closest("input, textarea, select")||n.closest('[contenteditable="true"]')):!1}function xe(e){const n=String(e.code||""),t=e.altKey&&e.shiftKey&&!e.ctrlKey&&!e.metaKey&&n==="KeyC",r=e.altKey&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&n==="KeyC",o=e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey&&n==="KeyY",l=e.metaKey&&e.shiftKey&&!e.altKey&&!e.ctrlKey&&n==="KeyY";return t||r||o||l}function be(e){try{if(!e.rangeCount)return"";const t=e.getRangeAt(0).cloneContents(),r=document.createElement("div");return r.appendChild(t),r.innerHTML.trim()}catch{return""}}async function Z(e){if(!c||e.defaultPrevented||W(e))return;const n=q(e.target);if(!n)return;const t=n.href||"";!t||!N(t,window.location.href)||(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),await v(t,document.referrer||window.location.href))}function ee(e){if(!c)return;const n=q(e.target);if(!n)return;const t=n.href||"";!t||!N(t,window.location.href)||W(e)||(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),v(t,document.referrer||window.location.href))}document.addEventListener("pointerdown",e=>{e.button===0&&ee(e)},!0);document.addEventListener("mousedown",e=>{e.button===0&&ee(e)},!0);document.addEventListener("click",e=>{e.button===0&&Z(e)},!0);document.addEventListener("keydown",e=>{if(!c||e.key!=="Enter"||e.defaultPrevented||W(e))return;const n=q(e.target);if(!n)return;const t=n.href||"";!t||!N(t,window.location.href)||(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),v(t,document.referrer||window.location.href))},!0);document.addEventListener("keydown",e=>{if(xe(e)&&(m("hotkey detected",{code:e.code,key:e.key,alt:e.altKey,shift:e.shiftKey,ctrl:e.ctrlKey,meta:e.metaKey,defaultPrevented:e.defaultPrevented,href:window.location.href}),!we(e.target))){if(!c){T("확장이 OFF 상태입니다.","error"),m("hotkey blocked: extension disabled");return}e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),D()}},!0);document.addEventListener("auxclick",e=>{e.button===1&&Z(e)},!0);function ke(){try{const e=window.open.bind(window);window.open=function(t,r,o){const l=String(t||"").trim();return c&&l&&N(l,window.location.href)?(v(l,window.location.href),null):e(t,r,o)}}catch{}try{const e=HTMLAnchorElement.prototype.click;HTMLAnchorElement.prototype.click=function(){const t=this.href||this.getAttribute("href")||"";if(c&&t&&N(t,window.location.href)){v(t,document.referrer||window.location.href);return}e.call(this)}}catch{}}ke();let E=null,h=null,H=!1,j=null,P=window.location.href,C=null,g=null,S=null,w=null;function Ee(e){try{const n=new URL(e);return n.hostname!=="www.youtube.com"&&n.hostname!=="youtube.com"?!1:n.pathname==="/watch"&&n.searchParams.has("v")}catch{return!1}}function K(e,n="idle"){h&&(h.textContent=e,n==="ok"?h.style.color="#8ff0a4":n==="error"?h.style.color="#ff9b9b":h.style.color="#aeb7d8")}async function Ce(){if(!H){H=!0,K("gdown으로 전송 중...");try{const e=await d.runtime.sendMessage({type:"page:enqueue-ytdlp-url",url:window.location.href,referer:window.location.href});e?.ok?K("다운로드 모달로 전송됨","ok"):K(`전송 실패: ${e?.error||"unknown error"}`,"error")}catch(e){K(`전송 실패: ${String(e)}`,"error")}finally{H=!1}}}function F(){E&&(E.remove(),E=null,h=null)}function x(){if(!c){F();return}if(window.top!==window.self)return;if(!Ee(window.location.href)){F();return}if(E)return;const e=document.createElement("div");e.id="gomdown-youtube-overlay",e.style.position="fixed",e.style.right="20px",e.style.bottom="24px",e.style.zIndex="2147483647",e.style.background="rgba(17, 21, 32, 0.94)",e.style.border="1px solid rgba(133, 148, 195, 0.35)",e.style.borderRadius="12px",e.style.padding="10px",e.style.boxShadow="0 8px 24px rgba(0, 0, 0, 0.28)",e.style.backdropFilter="blur(6px)",e.style.width="220px",e.style.fontFamily="ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif",e.style.color="#e8edff";const n=document.createElement("div");n.textContent="Gdown Helper",n.style.fontSize="12px",n.style.fontWeight="700",n.style.marginBottom="8px";const t=document.createElement("button");t.type="button",t.textContent="이 영상 다운로드",t.style.width="100%",t.style.height="34px",t.style.border="1px solid #5a69f0",t.style.borderRadius="8px",t.style.background="#5a69f0",t.style.color="#ffffff",t.style.fontSize="12px",t.style.fontWeight="700",t.style.cursor="pointer",t.addEventListener("click",()=>{Ce()});const r=document.createElement("div");r.textContent="클릭 시 gdown 다운로드 모달로 연결",r.style.fontSize="11px",r.style.marginTop="8px",r.style.lineHeight="1.35",r.style.color="#aeb7d8",e.appendChild(n),e.appendChild(t),e.appendChild(r),document.documentElement.appendChild(e),E=e,h=r}function Se(){j===null&&(j=window.setInterval(()=>{const e=window.location.href;e!==P&&(P=e,x())},800),window.addEventListener("popstate",()=>{P=window.location.href,x()}),document.addEventListener("yt-navigate-finish",()=>{P=window.location.href,x()}))}x();Se();function Te(){const e=window.getSelection(),t=(e&&e.rangeCount>0?e.getRangeAt(0):null)?.commonAncestorContainer||document.activeElement||null,r=t instanceof Element?t:t?.parentElement||null;if(!r)return"";const o=r.closest("a[href]");return String(o?.href||"").trim()}function u(e,n="idle"){g&&(g.textContent=e,n==="ok"?g.style.color="#92f0ad":n==="error"?g.style.color="#ffaaaa":g.style.color="#aeb7d8")}async function te(){u("현재 페이지 전송 중...");try{const e=await d.runtime.sendMessage({type:"page:enqueue-ytdlp-url",url:window.location.href,referer:window.location.href});if(!e?.ok){u(`실패: ${e?.error||"unknown error"}`,"error");return}u("현재 페이지 전송 완료","ok")}catch(e){u(`실패: ${String(e)}`,"error")}}async function ne(){const e=Te();if(e){u("선택 링크 전송 중...");try{const t=await d.runtime.sendMessage({type:"page:enqueue-ytdlp-url",url:e,referer:window.location.href});if(t?.ok){u("선택 링크 전송 완료","ok");return}u(`실패: ${t?.error||"unknown error"}`,"error");return}catch(t){u(`실패: ${String(t)}`,"error")}}if((await D()).ok){u("선택 텍스트 클립 저장","ok");return}u("선택 링크/텍스트가 없습니다.","error")}function z(){C&&(C.remove(),C=null,g=null)}function R(){S&&(S.style.display="none",w!==null&&(window.clearTimeout(w),w=null))}function Oe(){if(c){if(!S){const e=document.createElement("div");e.id="gomdown-quick-action-bar",e.style.position="fixed",e.style.left="50%",e.style.bottom="16px",e.style.transform="translateX(-50%)",e.style.zIndex="2147483647",e.style.display="flex",e.style.gap="8px",e.style.padding="10px",e.style.background="rgba(15, 19, 29, 0.94)",e.style.border="1px solid rgba(101, 116, 158, 0.48)",e.style.borderRadius="12px",e.style.boxShadow="0 12px 24px rgba(0, 0, 0, 0.28)",e.style.backdropFilter="blur(6px)";const n=(i,s,p=!1)=>{const a=document.createElement("button");return a.type="button",a.textContent=i,a.style.height="32px",a.style.padding="0 12px",a.style.borderRadius="8px",a.style.border=p?"1px solid #5968f2":"1px solid #4a556f",a.style.background=p?"#5968f2":"#273041",a.style.color="#e8edff",a.style.fontSize="12px",a.style.fontWeight="700",a.style.cursor="pointer",a.addEventListener("click",s),a},t=document.createElement("div");t.style.display="none",t.style.gap="6px",t.style.alignItems="center",t.style.flexWrap="wrap";const r=n("MD",()=>{d.runtime.sendMessage({type:"clip:export-current-page-md",pageUrl:window.location.href,pageTitle:document.title||window.location.href}).then(i=>{u(i?.ok?"MD 내보내기 완료":`실패: ${i?.error||"unknown error"}`,i?.ok?"ok":"error")}).catch(i=>{u(`실패: ${String(i)}`,"error")})}),o=n("JSON",()=>{d.runtime.sendMessage({type:"clip:export-current-page-json",pageUrl:window.location.href,pageTitle:document.title||window.location.href}).then(i=>{u(i?.ok?"JSON 내보내기 완료":`실패: ${i?.error||"unknown error"}`,i?.ok?"ok":"error")}).catch(i=>{u(`실패: ${String(i)}`,"error")})}),l=n("Obsidian",()=>{d.runtime.sendMessage({type:"clip:send-obsidian-current-page",pageUrl:window.location.href,pageTitle:document.title||window.location.href}).then(i=>{if(!i?.ok||!i?.uri){u(`실패: ${i?.error||"unknown error"}`,"error");return}try{window.open(String(i.uri),"_blank")}catch{window.location.href=String(i.uri)}u("Obsidian 전송 시도 완료","ok")}).catch(i=>{u(`실패: ${String(i)}`,"error")})});t.appendChild(r),t.appendChild(o),t.appendChild(l),e.appendChild(n("현재 페이지",()=>{te()})),e.appendChild(n("선택 항목",()=>{ne()},!0)),e.appendChild(n("클립 저장",()=>{D().then(i=>{i.ok&&(t.style.display="flex")})})),e.appendChild(n("닫기",()=>{R()})),e.appendChild(t),document.documentElement.appendChild(e),S=e}S.style.display="flex",w!==null&&window.clearTimeout(w),w=window.setTimeout(()=>{R()},8e3)}}function re(){if(!c){z(),R();return}if(window.top!==window.self||C)return;const e=document.createElement("div");e.id="gomdown-quick-panel",e.style.position="fixed",e.style.right="14px",e.style.top="42%",e.style.transform="translateY(-42%)",e.style.width="188px",e.style.zIndex="2147483647",e.style.padding="10px",e.style.borderRadius="12px",e.style.background="rgba(16, 20, 30, 0.94)",e.style.border="1px solid rgba(110, 125, 168, 0.42)",e.style.boxShadow="0 12px 24px rgba(0, 0, 0, 0.28)",e.style.backdropFilter="blur(6px)",e.style.display="grid",e.style.gap="7px",e.style.fontFamily="ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif";const n=document.createElement("div");n.textContent="Gdown Quick",n.style.fontSize="12px",n.style.fontWeight="700",n.style.color="#e8edff";const t=document.createElement("button");t.type="button",t.textContent="현재 페이지",t.style.height="30px",t.style.border="1px solid #5766ef",t.style.borderRadius="8px",t.style.background="#5766ef",t.style.color="#ffffff",t.style.fontSize="12px",t.style.fontWeight="700",t.style.cursor="pointer",t.addEventListener("click",()=>{te()});const r=document.createElement("button");r.type="button",r.textContent="선택 항목",r.style.height="30px",r.style.border="1px solid #4d566f",r.style.borderRadius="8px",r.style.background="#2a3040",r.style.color="#dce5ff",r.style.fontSize="12px",r.style.fontWeight="700",r.style.cursor="pointer",r.addEventListener("click",()=>{ne()});const o=document.createElement("div");o.textContent="현재 페이지/선택 항목 빠른 처리",o.style.fontSize="11px",o.style.lineHeight="1.35",o.style.color="#aeb7d8",e.appendChild(n),e.appendChild(t),e.appendChild(r),e.appendChild(o),document.documentElement.appendChild(e),C=e,g=o}function Ne(e){return e.color==="yellow","rgba(255, 235, 87, 0.58)"}function A(){const e=Array.from(document.querySelectorAll("span[data-gomdown-clip]"));for(const n of e){const t=n.parentNode;if(t){for(;n.firstChild;)t.insertBefore(n.firstChild,n);t.removeChild(n)}}}function T(e,n="ok"){const t=ie();t.textContent=e,t.style.display="block",t.style.borderColor=n==="ok"?"rgba(123, 190, 124, 0.55)":"rgba(200, 113, 113, 0.55)",t.style.color=n==="ok"?"#dffbe4":"#ffe4e4",f!==null&&window.clearTimeout(f),f=window.setTimeout(()=>{t.style.display="none",f=null,t.style.borderColor="rgba(128, 140, 180, 0.42)",t.style.color="#dce4fa"},1800)}function Me(e){const n=me(e.anchor);if(!n||n.collapsed)return!1;const t=document.createElement("span");t.dataset.gomdownClip=e.id,t.style.background=Ne(e),t.style.padding="0.04em 0.03em",t.style.borderRadius="0.12em",t.style.boxDecorationBreak="clone",t.style.setProperty("-webkit-box-decoration-break","clone"),t.style.cursor="pointer",t.title=e.quote||"clip",t.addEventListener("click",r=>{(r.altKey||r.metaKey||r.ctrlKey)&&(r.stopPropagation(),r.preventDefault())});try{const r=n.extractContents();return t.appendChild(r),n.insertNode(t),!0}catch{return!1}}async function ve(e,n){await d.runtime.sendMessage({type:"clip:resolve-status",id:e,status:n}).catch(()=>null)}function J(e){const n=document.querySelector(`span[data-gomdown-clip="${CSS.escape(e)}"]`);return n?(n.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"}),n.animate([{boxShadow:"0 0 0 0 rgba(255, 250, 164, 0.2)"},{boxShadow:"0 0 0 8px rgba(255, 250, 164, 0.65)"},{boxShadow:"0 0 0 0 rgba(255, 250, 164, 0.2)"}],{duration:760,easing:"ease-out"}),!0):!1}async function Re(e){return J(e)?!0:(await b(!0),J(e))}async function b(e=!1){if(!c)return;const n=++U,t=M(window.location.href),r=[0,700,1900];let o=0,l=0;for(let i=0;i0&&(await new Promise(y=>window.setTimeout(y,s)),n!==U))return;const p=await d.runtime.sendMessage({type:"clip:list",pageUrl:t});if(!p?.ok||!Array.isArray(p.items))return;A();const a=[...p.items].sort((y,L)=>{const le=Number(y.anchor.startTextOffset||0);return Number(L.anchor.startTextOffset||0)-le});let $=0;const B=[];for(const y of a)Me(y)?$+=1:B.push(y.id);if(o=$,l=a.length,B.length===0||i===r.length-1){const y=new Set(B);await Promise.all(a.map(L=>ve(L.id,y.has(L.id)?"broken":"ok")));break}}e&&T(`클립 복원: ${o}/${l}`,o>0?"ok":"error")}async function D(){if(!c)return{ok:!1,error:"extension disabled"};const e=window.getSelection();if(m("createClipFromCurrentSelection:start",{hasSelection:!!e,selectedTextLength:Number(e?.toString()?.length||0),href:window.location.href}),!e)return{ok:!1,error:"selection unavailable"};const n=ye(e);if(!n)return T("선택된 텍스트가 없습니다.","error"),m("createClipFromCurrentSelection:fail","empty selection"),{ok:!1,error:"empty selection"};const t=await d.runtime.sendMessage({type:"clip:create",pageUrl:M(window.location.href),pageTitle:document.title||window.location.href,quote:String(n.quote||"").trim(),quoteHtml:be(e),anchor:n.anchor});return!t?.ok||!t.item?(T(`클립 저장 실패: ${t?.error||"unknown error"}`,"error"),m("createClipFromCurrentSelection:fail",t?.error||"create failed"),{ok:!1,error:t?.error||"create failed"}):(A(),await b(),T("클립 저장 완료 (Alt+Shift+C)","ok"),m("createClipFromCurrentSelection:ok",{id:t.item.id,pageUrl:t.item.pageUrl}),{ok:!0})}function Le(){V===null&&(V=window.setInterval(()=>{const e=M(window.location.href);e!==I&&(I=e,b())},900),window.addEventListener("popstate",()=>{const e=M(window.location.href);e!==I&&(I=e,b())}))}Le();let O=null,f=null;function oe(){O&&(O.style.display="none",f!==null&&(window.clearTimeout(f),f=null))}function ie(){if(O)return O;const e=document.createElement("div");return e.id="gomdown-media-toast",e.style.position="fixed",e.style.left="18px",e.style.bottom="18px",e.style.zIndex="2147483647",e.style.maxWidth="360px",e.style.padding="10px 12px",e.style.borderRadius="10px",e.style.border="1px solid rgba(128, 140, 180, 0.42)",e.style.background="rgba(18, 21, 31, 0.95)",e.style.color="#dce4fa",e.style.fontSize="12px",e.style.lineHeight="1.35",e.style.fontFamily="ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif",e.style.boxShadow="0 10px 24px rgba(0, 0, 0, 0.28)",e.style.display="none",document.documentElement.appendChild(e),O=e,e}function Ie(e){if(!c)return;const n=ie(),t=String(e?.kind||"media").toUpperCase(),r=String(e?.suggestedOut||"").trim(),o=String(e?.url||"").trim().slice(0,96);n.textContent=r?`캡처됨 [${t}] ${r}`:`캡처됨 [${t}] ${o}${o.length>=96?"…":""}`,n.style.display="block",f!==null&&window.clearTimeout(f),f=window.setTimeout(()=>{n.style.display="none",f=null},2200)}d.runtime.onMessage.addListener(e=>{if(e?.type==="clip:ping")return m("runtime.onMessage clip:ping"),{ok:!0};if(e?.type==="clip:create-from-selection")return m("runtime.onMessage clip:create-from-selection"),D();if(e?.type==="clip:show-action-bar")return Oe(),{ok:!0};if(e?.type==="media:captured"){Ie({kind:e?.kind,url:e?.url,suggestedOut:e?.suggestedOut});return}if(e?.type==="clip:reveal"){const n=String(e?.id||"").trim();return n?Re(n).then(t=>({ok:t})):void 0}});async function Pe(){try{c=!!(await se()).extensionStatus}catch{c=!1}c?(x(),re(),await b()):(F(),z(),R(),oe(),A())}Pe();d.storage.onChanged.addListener((e,n)=>{if(n==="sync"&&e.extensionStatus){if(c=!!e.extensionStatus.newValue,!c){F(),z(),R(),oe(),A();return}x(),re(),b()}});