import{r as K,a as O,o as U,i as F,n as z}from"./chunk-Ci5y0mdV.js";import{c as j}from"./chunk-DKjNeJAl.js";import{p as q}from"./chunk-BvQ1SBzo.js";import{c as J}from"./chunk-YE5gLsn5.js";function W(){const e=location.hash.startsWith("#")?location.hash.slice(1):"";if(e)try{const s=new URL(e),f=s.hostname.replace(/\.$/,"").toLowerCase(),l=f.match(/^(0x[a-f0-9]{40})\.w3eth\.io$/i);return l&&l[1]?{ensName:l[1].toLowerCase(),path:s.pathname||"/",search:s.search,hash:s.hash,mode:"address"}:{ensName:f,path:s.pathname||"/",search:s.search,hash:s.hash,mode:"ens"}}catch{}const t=new URLSearchParams(location.search),o=(t.get("name")??"").toLowerCase(),r=/^0x[a-f0-9]{40}$/i.test(o)?"address":"ens";return{ensName:o,path:t.get("path")??"/",search:t.get("search")??"",hash:t.get("hash")??"",mode:r}}const{ensName:n,path:i,search:h,hash:m,mode:_}=W(),d=_==="address";document.title=n?`resolving ${d?G(n):n}…`:"dapp3.eth";function G(e){return e.length>12?`${e.slice(0,6)}…${e.slice(-4)}`:e}const g=document.getElementById("name"),w=document.getElementById("status"),H=document.getElementById("bar"),C=document.getElementById("loader"),Q=document.getElementById("bypass"),a=document.getElementById("star"),b=document.getElementById("statusBadge"),A=document.getElementById("statusDot"),V=document.getElementById("statusLabel"),v=document.getElementById("stageSub"),L=document.getElementById("errorCard"),X=document.getElementById("errorDetail"),y=document.getElementById("ethlimoFallback"),P=document.getElementById("ensHistory"),x=document.getElementById("setupCard"),Y=document.getElementById("setupCmd"),Z=document.getElementById("setupJson"),k=document.getElementById("setupRecheck"),c=document.getElementById("setupStatus");!d&&n&&/^(?:[a-z0-9-]+\.)+eth$/.test(n)&&(P.href=`https://ens.eth.sh/history/${n}`,P.hidden=!1);function ee(){const e=i.startsWith("/")?i:`/${i}`;return d?/^0x[a-f0-9]{40}$/.test(n)?`https://${n}.w3eth.io${e}${h}${m}`:null:/^(?:[a-z0-9-]+\.)+eth$/.test(n)?`https://${n}.limo${e}${h}${m}`:null}function $(e){X.textContent=e,L.hidden=!1,v.hidden=!0;const t=ee();t&&(y.href=t,y.textContent=d?"Open on w3eth.io →":"Open on eth.limo gateway →",y.hidden=!1)}function R(){L.hidden=!0,v.hidden=!1,y.hidden=!0}const te=`ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["chrome-extension://${chrome.runtime.id}"]' && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["POST"]'`;Y.textContent=te;Z.innerHTML=J(["{","  ...",'  "API": {','    "HTTPHeaders": {',"      ...",'      "Access-Control-Allow-Methods": ["POST"],','      "Access-Control-Allow-Origin": [',"        ...,",`        "chrome-extension://${chrome.runtime.id}"`,"      ]","    }","  },","  ...","}"].join(`
`));function ne(){L.hidden=!0,y.hidden=!0,v.hidden=!0,C.hidden=!0,w.textContent="Kubo needs one-time setup",x.hidden=!1}function M(){x.hidden=!0,C.hidden=!1}function p(e,t){c.hidden=!1,c.classList.remove("ok","warn","bad"),c.classList.add(e),c.textContent=t}function N(){c.hidden=!0,c.textContent="",c.classList.remove("ok","warn","bad")}x.querySelectorAll(".setup-copy").forEach(e=>{const t=e.querySelector(".setup-copy-label");e.addEventListener("click",async()=>{const o=e.dataset.target;if(!o)return;const r=document.getElementById(o),s=r?.textContent??"";if(s){try{await navigator.clipboard.writeText(s)}catch{if(r){const f=document.createRange();f.selectNodeContents(r);const l=window.getSelection();l?.removeAllRanges(),l?.addRange(f)}return}e.classList.add("copied"),t&&(t.textContent="Copied"),setTimeout(()=>{e.classList.remove("copied"),t&&(t.textContent="Copy")},1500)}})});k.addEventListener("click",async()=>{k.disabled=!0,p("warn","Probing Kubo API…");const e=await q();if(!e.ok){k.disabled=!1,e.kind.kind==="cors"?p("bad","Kubo is still rejecting this extension's origin. Did the daemon restart?"):e.kind.kind==="unreachable"?p("bad",`Can't reach Kubo at 127.0.0.1:5001. Is IPFS Desktop running? (${e.kind.cause})`):p("bad",`Kubo returned an unexpected response: ${e.kind.kind}.`);return}p("ok","Kubo allowed the extension. Retrying…"),M(),N(),await I(!1)});function u(e,t,o){b.classList.remove("ok","syncing","warn"),A.classList.remove("ok","syncing","warn"),b.classList.add(e),A.classList.add(e),V.textContent=t,b.title=o}function D(e){if(!e){u("warn","Helios offline","Helios has not started yet.");return}switch(e.state){case"idle":u("warn","Helios offline","Helios has not started yet.");return;case"booting":u("syncing","Helios booting","Helios is starting up against your execution RPC.");return;case"syncing":u("syncing","Helios syncing","Helios is catching up to the chain tip.");return;case"synced":u("ok","Helios online","Helios is in sync with Ethereum consensus and ready to verify.");return;case"error":u("warn","Helios error",`Helios error: ${e.error??"unknown"}`);return}}D(void 0);const B=`${i==="/"?"":i}${h}${m}`;if(n)if(d){g.textContent="";const e=document.createElement("span");if(e.className="u-host",e.textContent=n,e.title=n,g.appendChild(e),B){const t=document.createElement("span");t.className="u-path",t.textContent=B,g.appendChild(t)}}else j(g,`${n}${B}`);else g.textContent="(no name)";let S=!0;async function se(){if(!n)return!1;try{const e=await chrome.runtime.sendMessage({type:"interstitial-cache-check",name:n,path:i,search:h,hash:m});if(e?.cached&&typeof e.gatewayUrl=="string")return S=!1,location.replace(e.gatewayUrl),!0}catch{}return!1}function E(e){H.classList.remove("ok","bad"),C.classList.remove("ok","bad"),e!=="loading"&&(H.classList.add(e),C.classList.add(e))}function oe(e){switch(e.state){case"idle":return"Helios is not yet running.";case"booting":return"Starting Helios…";case"syncing":return"Syncing with Ethereum consensus…";case"synced":return"Synced. Resolving…";case"error":return"Helios sync failed"}}async function I(e=!1){S=!1,w.textContent=e?"Resolving via RPC (skipping Helios)…":d?"Fetching onchain HTML…":"Fetching ENS contenthash…",E("loading"),M(),N();const t=await chrome.runtime.sendMessage({type:"interstitial-retry",name:n,path:i,search:h,hash:m,bypassHelios:e});if(!t?.ok){if(t?.code==="kubo-cors-blocked"){ne(),E("bad");return}w.textContent="Resolution failed",$(t?.error??"Unknown error"),E("bad")}}async function ae(){for(;S;){try{const t=(await chrome.runtime.sendMessage({type:"get-helios-status"}))?.status;if(t){if(w.textContent=oe(t),D(t),t.state==="synced"){R(),await I(!1);return}t.state==="error"?(E("bad"),$(t.error??"Unknown error")):R()}}catch(e){const t=e instanceof Error?e.message:String(e);w.textContent="Status check failed",$(t)}await new Promise(e=>setTimeout(e,750))}}Q.addEventListener("click",()=>I(!0));function T(e){const t=a.querySelector("svg");e?(a.classList.add("favorited"),a.setAttribute("title","Remove from favorites"),a.setAttribute("aria-pressed","true"),t?.setAttribute("fill","currentColor")):(a.classList.remove("favorited"),a.setAttribute("title","Favorite this site"),a.setAttribute("aria-pressed","false"),t?.setAttribute("fill","none"))}if(n&&!d){const e=z(`${i}${h}${m}`||"/");(async()=>{T(await F(n,e))})(),a.addEventListener("click",async o=>{if(o.stopPropagation(),a.classList.contains("favorited"))await K(n,e);else{const r={ensName:n,path:e,addedAt:Date.now()};await O(r)}}),U(o=>{const r=o.some(s=>s.ensName===n&&s.path===e);T(r)})}else a.hidden=!0;(async()=>await se()||ae())();
//# sourceMappingURL=interstitial-Bt83OTIv.js.map
