import{c as w,p as k,e as $,i as B,n as z}from"./index-tiSqwqFl.js";import{h as P}from"./hood-logo-CePbdOqP.js";const b="data-hoodwallet-injected",l="hoodwallet-trade-button",u="hoodwallet-inline-button",j=[/axiom\.trade\/t\/([1-9A-HJ-NP-Za-km-z]{32,44})/i,/bullx\.io\/terminal\?.*address=([1-9A-HJ-NP-Za-km-z]{32,44})/i,/birdeye\.so\/token\/([1-9A-HJ-NP-Za-km-z]{32,44})/i,/photon-sol\.tinyastro\.io\/[^/]+\/r\/@\/([1-9A-HJ-NP-Za-km-z]{32,44})/i];function W(){const e=k(window.location.href)[0]?.token;return e&&e.chainId!=="solana"?e.chainId:"1"}function _(e){const t=e.trim();return B(t)?{chainId:W(),address:z(t)}:$(t)?{chainId:"solana",address:t}:null}function A(e){const t=k(e)[0]?.token;if(t)return t;for(const n of j){const o=e.match(n)?.[1];if(o&&$(o))return{chainId:"solana",address:o}}return null}function F(e,t=6){let n=e;for(let o=0;o<t&&n;o+=1){if(n instanceof HTMLAnchorElement){const s=A(n.href);if(s)return s}for(const s of n.querySelectorAll("a[href]")){const i=A(s.href);if(i)return i}for(const s of["data-address","data-mint","data-token","data-ca","data-contract","data-token-address"]){const i=n.getAttribute(s);if(!i)continue;const d=_(i);if(d)return d}const r=n.textContent?.trim()??"";if(r.length>31&&r.length<500){const s=w(r,window.location.href)[0]?.token;if(s)return s}n=n.parentElement}return k(window.location.href)[0]?.token??null}function M(){if(document.getElementById("hoodwallet-inject-styles"))return;const e=document.createElement("style");e.id="hoodwallet-inject-styles",e.textContent=`
.${l} {
  all: initial;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 25px;
  margin-left: 6px;
  padding: 4px 9px 4px 6px;
  border: 1px solid rgba(16, 227, 134, .35);
  border-radius: 999px;
  background: linear-gradient(135deg, #10e386 0%, #00d7ff 52%, #32b4ff 100%);
  color: #fff;
  box-shadow: 0 5px 18px rgba(0, 215, 255, .28), inset 0 1px rgba(255, 255, 255, .22);
  cursor: pointer;
  font: 700 9px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
  opacity: .9;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
  position: relative;
  z-index: 999;
}
.${l}:hover {
  transform: translateY(-1px) scale(1.02);
  opacity: 1;
  box-shadow: 0 8px 24px rgba(0, 215, 255, .42), inset 0 1px rgba(255, 255, 255, .24);
}
.${l}:active { transform: scale(.97); }
.${l} .hoodwallet-mark {
  display: block;
  width: 15px;
  height: 15px;
  border-radius: 4px;
  background: #050509 url('${P}') center / cover no-repeat;
}
.${u} {
  all: initial;
  box-sizing: border-box;
  display: inline-grid;
  width: 20px;
  height: 20px;
  margin: 0 3px;
  place-items: center;
  border: 1px solid rgba(216, 200, 255, .48);
  border-radius: 7px;
  color: #fff;
  background: linear-gradient(145deg, #10e386 0%, #00d7ff 58%, #32b4ff);
  box-shadow: inset 0 1px rgba(255, 255, 255, .3), 0 3px 10px rgba(0, 215, 255, .35);
  cursor: pointer;
  font: 850 10px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  vertical-align: middle;
  transform: translateY(-1px);
  transition: transform .14s ease, box-shadow .14s ease;
  position: relative;
  z-index: 999;
}
.${u}:hover {
  transform: translateY(-2px) scale(1.08);
  box-shadow: inset 0 1px rgba(255, 255, 255, .3), 0 5px 15px rgba(0, 215, 255, .45);
}
.${u}:active { transform: scale(.95); }
`,document.head.appendChild(e)}function R(e){const t=(e.textContent??"").trim().toLowerCase();if(!t||t.length>28||!["buy","trade","swap","snipe","quick buy"].some(o=>t===o||t.startsWith(o)))return!1;const n=e.getBoundingClientRect();return!n.width||!n.height||n.width>240||n.height>72||e.nextElementSibling?.classList.contains(l)?!1:!e.parentElement?.querySelector(`:scope > .${l}`)}function C(e){const t={type:"OPEN_WITH_TOKEN",token:e,pageUrl:window.location.href};chrome.runtime.sendMessage(t).catch(()=>{})}function q(e){const t=document.createElement("button");return t.className=l,t.type="button",t.setAttribute(b,"true"),t.title=`Open ${e.address.slice(0,6)}...${e.address.slice(-4)} in HoodWallet`,t.innerHTML='<span class="hoodwallet-mark"></span><span>HoodWallet</span>',t.addEventListener("click",n=>{n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation(),C(e)},!0),t}function E(e){const t=document.createElement("button");return t.className=u,t.type="button",t.textContent="1",t.setAttribute(b,"true"),t.dataset.hoodwalletToken=`${e.chainId}:${e.address}`,t.setAttribute("aria-label",`Open ${e.address} in HoodWallet`),t.title=`Open ${e.address.slice(0,6)}...${e.address.slice(-4)} in HoodWallet`,t.addEventListener("click",n=>{n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation(),C(e)},!0),t}function L(e){const t=e.dataset.hoodwalletToken??"";return t.slice(t.indexOf(":")+1).toLowerCase()}function N(e){return e.closest('article, [role="article"], [data-testid="tweet"]')??e.parentElement??e}function J(e,t){const n=t.toLowerCase();return[...e.querySelectorAll(`.${u}[data-hoodwallet-token]`)].some(o=>L(o)===n)}function D(){const e=new Map,t=document.querySelectorAll(`.${u}[data-hoodwallet-token]`);for(const n of t){const o=n.dataset.hoodwalletToken;if(!o)continue;const r=N(n),s=o.indexOf(":"),i=o.slice(0,s),d=L(n),f=e.get(r)??new Map,p=f.get(d);if(!p){f.set(d,n),e.set(r,f);continue}const m=p.dataset.hoodwalletToken??"";m.slice(0,m.indexOf(":"))==="1"&&i!=="1"?(p.remove(),f.set(d,n)):n.remove()}}function U(){if(!document.body)return;D();const e=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT);let t=0;for(;e.nextNode()&&t<2200;){t+=1;const n=e.currentNode,o=n.textContent??"",r=n.parentElement;if(!r||o.trim().length<32||!/(?:0x[a-fA-F0-9]{40}|[1-9A-HJ-NP-Za-km-z]{32,44})/.test(o)||r.closest(`script, style, noscript, textarea, input, [contenteditable="true"], .${l}, .${u}`))continue;const s=r.getBoundingClientRect();if(!s.width||!s.height||s.bottom<0||s.top>window.innerHeight)continue;const i=w(o,window.location.href);if(!i.length)continue;const f=(r.closest('article, [role="article"], main, section')??r.parentElement)?.textContent?.slice(0,5e3)??o,p=w(f,window.location.href),m=i.map(a=>{const x=p.find(h=>h.token.address.toLowerCase()===a.token.address.toLowerCase())?.token??a.token;return{token:x,index:o.toLowerCase().indexOf(x.address.toLowerCase())}}).filter(a=>a.index>=0).sort((a,c)=>c.index-a.index);for(const a of m){const{token:c}=a,x=`${c.chainId}:${c.address}`,h=r.closest("a"),y=h??r,H=N(y);if(y.nextElementSibling?.dataset.hoodwalletToken!==x&&!J(H,c.address))if(h)h.insertAdjacentElement("afterend",E(c));else{const v=n.splitText(a.index),O=v.splitText(c.address.length);v.parentNode?.insertBefore(E(c),O)}}}}function S(){U();const e=document.querySelectorAll('button, a[href], [role="button"]');for(const t of e){if(t.hasAttribute(b)||t.closest(`.${l}`)||!R(t))continue;const n=t.closest('tr, [class*="row"], [class*="card"], [class*="token"]'),o=F(n??t);o&&(t.setAttribute(b,"true"),t.insertAdjacentElement("afterend",q(o)))}}M();S();let g;function T(e=250){g===void 0&&(g=setTimeout(()=>{g=void 0,S()},e))}const Z=new MutationObserver(()=>T(60));document.body&&Z.observe(document.body,{childList:!0,characterData:!0,subtree:!0});window.addEventListener("scroll",()=>T(160),{passive:!0});let I=window.location.href;window.setInterval(()=>{window.location.href!==I&&(I=window.location.href,T(500))},1e3);
