import{p as D,m as w,b as C,c as T}from"./index-tiSqwqFl.js";import{g as f,i as v,s as E}from"./pageIntent-Dnd3UM4a.js";let u="",k=!1;const m=new Map;function p(e){return e.map(t=>{if(t.token.chainId!=="1"&&t.token.chainId!=="solana")return m.set(t.token.address.toLowerCase(),t.token.chainId),t;if(t.token.chainId!=="1")return t;const n=m.get(t.token.address.toLowerCase());return n?{...t,token:{...t.token,chainId:n}}:t})}function S(e=8e3){if(!document.body)return"";const t=[];let n=0,r=0;const o=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT);for(;o.nextNode()&&n<e&&r<1800;){r+=1;const s=o.currentNode,a=s.textContent?.trim(),c=s.parentElement;if(!a||!c||c.closest('script, style, noscript, [aria-hidden="true"]'))continue;const l=window.getComputedStyle(c);if(l.display==="none"||l.visibility==="hidden"||Number(l.opacity)===0)continue;const h=document.createRange();h.selectNodeContents(s);const d=h.getBoundingClientRect();if(h.detach(),d.width===0||d.height===0||d.bottom<0||d.top>window.innerHeight||d.right<0||d.left>window.innerWidth)continue;const y=e-n;t.push(a.slice(0,y)),n+=Math.min(a.length,y)+1}return t.join(" ")}function I(){const e=new Set,t=document.querySelector('link[rel="canonical"]')?.href;t&&e.add(t);for(const n of document.querySelectorAll('meta[property="og:url"], meta[name="twitter:url"]')){const r=n.content?.trim();r&&e.add(r)}return[...e]}function M(e,t){const n=[],r=["data-address","data-mint","data-token","data-ca","data-contract","data-token-address"];for(const o of document.querySelectorAll("[data-address], [data-mint], [data-token], [data-ca], [data-contract], [data-token-address]"))for(const s of r){const a=o.getAttribute(s)?.trim();if(!a)continue;const c=T(a,e,t);n.push(...c.map(l=>({...l,confidence:"medium"})))}return n}function x(e,t){const n=f(e);let o=D(e,t,n==="token-detail"?"full":"primary");if(n==="token-detail"&&(o=w(o,C(I(),e,t))),o.some(c=>c.confidence==="high")||!E(e,n))return p(o);const a=w(T(S(),e,t),M(e,t));return p(w(o,a)).slice(0,3)}function F(){k=!1;const e=window.location.href,t=Date.now(),n=x(e,t),r=`${f(e)}:${n.map(s=>`${s.token.chainId}:${s.token.address}`).join(",")}`;if(r===u)return;u=r;const o={type:"TOKEN_DETECTED",tokens:n,pageUrl:e};chrome.runtime.sendMessage(o).catch(()=>{})}function i(){k||(k=!0,requestAnimationFrame(F))}i();const N=new MutationObserver(()=>{i()});document.body&&N.observe(document.body,{childList:!0,characterData:!0,subtree:!0});window.addEventListener("popstate",()=>{u="",m.clear(),i()});let b;window.addEventListener("scroll",()=>{const e=window.location.href;f(e)==="browse"&&!v(e)||(clearTimeout(b),b=setTimeout(i,120))},{passive:!0});window.addEventListener("resize",i,{passive:!0});let g=window.location.href;setInterval(()=>{window.location.href!==g&&(g=window.location.href,u="",m.clear(),i())},400);setInterval(()=>{const e=window.location.href;f(e)==="browse"&&!v(e)||i()},3e3);
