PageSourceSearch

https://conversiontab.com/build/assets/api-tester-page-BV-oEt8h.js

js conversiontab.com collected 2026-09-24 10:06:58 UTC 24,581 bytes, 17 lines download raw bytes

1import{T as Rt}from"./app-gOHIPY12.js";function u(C,g=!0){const E=document.getElementById("ctApiToast"),m=document.getElementById("ctApiToastBody");if(!E||!m){window.alert(C);return}m.textContent=C,E.classList.remove("text-bg-success","text-bg-danger"),E.classList.add(g?"text-bg-danger":"text-bg-success"),Rt.getOrCreateInstance(E,{delay:5e3}).show()}const Lt="https://jsonplaceholder.typicode.com/todos/1",It=new Set(["localhost","127.0.0.1","::1"]);function Ue(C){const g=String(C||"").trim();if(!g)return{ok:!1,error:"Enter a URL."};let E=g;if(!/^https?:\/\//i.test(g)){if(g.startsWith("/")||g.startsWith("./")||g.startsWith("../"))return{ok:!1,error:"Use a full URL (http:// or https://), not a site path."};E=`https://${g}`}let m;try{m=new URL(E)}catch{return{ok:!1,error:"Invalid URL."}}return m.protocol!=="http:"&&m.protocol!=="https:"?{ok:!1,error:"Only http:// and https:// are supported."}:m.origin===window.location.origin?{ok:!1,error:"Enter the API address to call — not a ConversionTab page path."}:{ok:!0,url:m.href}}function St(){const C=document.getElementById("ct-api-tester-root");if(!C)return;const g=document.getElementById("ctApiMethod"),E=document.getElementById("ctApiUrl"),m=document.getElementById("ctApiSend"),Pe=(m==null?void 0:m.textContent)||"Send",S=document.getElementById("ctApiResponseBody"),ge=document.getElementById("ctApiResponseHeaders"),ue=document.getElementById("ctApiMeta"),Q=document.getElementById("ctApiCopy"),X=document.getElementById("ctApiDownload"),Z=document.getElementById("ctApiFormatResponse"),me=document.getElementById("ctApiDownloadName"),pe=document.getElementById("ctApiRuntimeWarning"),Y=document.getElementById("ctApiQueryRows"),P=document.getElementById("ctApiHeaderRows"),ee=document.getElementById("ctApiFormDataRows"),te=document.getElementById("ctApiUrlEncRows"),He=document.getElementById("ctApiAddQueryRow"),Ne=document.getElementById("ctApiAddHeaderRow"),Je=document.getElementById("ctApiAddFormDataRow"),De=document.getElementById("ctApiAddUrlEncRow"),Oe=document.getElementById("ctApiAddEnvRow"),he=document.getElementById("ctApiHeaderType"),je=document.getElementById("ctApiHeadersJson"),We=document.getElementById("ctApiImportHeadersJson"),H=document.getElementById("ctApiBodyMode"),ne=document.getElementById("ctApiBodyRawType"),Ee=document.getElementById("ctApiBodyHelp"),Fe=document.getElementById("ctApiRawWrap"),_e=document.getElementById("ctApiRawTypeWrap"),Ke=document.getElementById("ctApiFormDataWrap"),ze=document.getElementById("ctApiUrlEncWrap"),N=document.getElementById("ctApiBodyRaw"),ve=document.getElementById("ctApiJsonFile"),Ge=document.getElementById("ctApiFormatJson"),J=document.getElementById("ctApiAuthType"),F=document.getElementById("ctApiAuthValue"),oe=document.getElementById("ctApiEnvRows"),Ve=document.getElementById("ctApiImportCollection"),Qe=document.getElementById("ctApiImportCollectionJson"),Xe=document.getElementById("ctApiExportCollection"),ae=document.getElementById("ctApiCollectionFile"),be=document.getElementById("ctApiCollectionJsonWrap"),Ze=document.getElementById("ctApiCollectionJson"),Ye=document.getElementById("ctApiApplyCollectionJson"),we=document.getElementById("ctApiCollectionList"),Ae=document.getElementById("ctApiRequestTabs"),et=document.getElementById("ctApiNewCollection"),Re=document.getElementById("ctApiToggleExplorer"),Le=C.querySelector(".ct-workspace"),Ie=It;let h=[],D="",re="",x="",tt=1,_=[],T=null,O="application/octet-stream",B="none",q="";const j=document.getElementById("ctApiRespViewRaw"),v=document.getElementById("ctApiRespViewPreview"),Be=document.getElementById("ctApiResponseRawWrap"),Se=document.getElementById("ctApiResponsePreviewWrap"),b=document.getElementById("ctApiPreviewImg"),w=document.getElementById("ctApiPreviewIframe");function nt(){return Ie.has(window.location.hostname)}function ot(e){const t=String(e||"").trim().toLowerCase();return t?!!(Ie.has(t)||t.endsWith(".local")||/^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(t)||/^192\.168\.\d{1,3}\.\d{1,3}$/.test(t)||/^172\.(1[6-9]|2\d|3[0-1])\.\d{1,3}\.\d{1,3}$/.test(t)):!1}function $(e=""){pe&&(pe.textContent=e,pe.classList.toggle("d-none",!e))}function ke(e){try{const t=new URL(e),o=ot(t.hostname),r=window.location.protocol==="https:",a=t.protocol==="http:",s=!nt()&&o;return{parsed:t,targetIsLocal:o,fromRemotePageToLocalTarget:s,mixedContentRisk:r&&a}}catch{return null}}function at(e){const t=ke(e);return t!=null&&t.fromRemotePageToLocalTarget?`Request blocked: this site cannot reach ${t.parsed.host} on your machine/private network. Open the tester on the same local environment (for example localhost) or expose the API with a public tunnel.`:t!=null&&t.mixedContentRisk?"Request blocked by browser mixed-content policy (HTTPS page to HTTP API). Use an HTTPS API endpoint.":"Request failed before receiving a response. Common causes: CORS, network/DNS issues, invalid SSL certificate, or the API server being offline."}function L(e){const t=[];return e.querySelectorAll(".ct-kv-row").forEach(o=>{var n,c,l,d;const r=((n=o.querySelector('[data-role="enabled"]'))==null?void 0:n.checked)!==!1,a=((l=(c=o.querySelector('[data-role="key"]'))==null?void 0:c.value)==null?void 0:l.trim())||"",s=((d=o.querySelector('[data-role="value"]'))==null?void 0:d.value)??"";r&&a&&t.push({key:a,value:s})}),t}function rt(e){const t=String(e||"").trim();if(!t)return{};const o=JSON.parse(t);if(o===null||typeof o!="object"||Array.isArray(o))throw new Error("Headers JSON must be an object");const r={};for(const[a,s]of Object.entries(o))!String(a||"").trim()||s==null||(r[String(a)]=String(s));return r}function st(){const e={};return L(oe).forEach(({key:t,value:o})=>{e[t]=o}),e}function I(e,t,o){return String(e??"").replace(/\{\{\s*([a-zA-Z0-9_.-]+)\s*\}\}/g,(a,s)=>Object.prototype.hasOwnProperty.call(t,s)?t[s]:(o.add(s),`{{${s}}}`))}function se(e,t,o=!0){let r;if(P.querySelectorAll(".ct-kv-row").forEach(a=>{var n,c;((c=(n=a.querySelector('[data-role="key"]'))==null?void 0:n.value)==null?void 0:c.trim().toLowerCase())===e.trim().toLowerCase()&&(r=a)}),r){r.querySelector('[data-role="enabled"]').checked=o,r.querySelector('[data-role="value"]').value=t;return}k(P,{key:e,value:t,enabled:o})}function k(e,{key:t="",value:o="",enabled:r=!0}={}){const a=document.createElement("div");
1a.className="ct-kv-row mb-2",a.innerHTML=`
2            <div class="form-check m-0 d-flex justify-content-center">
3                <input class="form-check-input mt-0" type="checkbox" data-role="enabled" ${r?"checked":""} />
4            </div>
5            <input type="text" class="form-control form-control-sm" placeholder="Key" data-role="key" value="${t.replace(/"/g,"&quot;")}">
6            <input type="text" class="form-control form-control-sm" placeholder="Value" data-role="value" value="${String(o).replace(/"/g,"&quot;")}">
7            <button type="button" class="btn btn-outline-danger btn-sm" data-role="remove" title="Remove row">×</button>
8        `,a.querySelector('[data-role="remove"]').addEventListener("click",()=>a.remove()),e.appendChild(a)}function lt(e){e.innerHTML=""}function K(e,t=[]){lt(e),t.forEach(o=>k(e,o)),t.length||k(e)}function ct(e){if(!e)return"";if(typeof e=="string")return e;if(e.raw)return String(e.raw);const t=e.protocol||"https",o=Array.isArray(e.host)?e.host.join("."):e.host||"",r=Array.isArray(e.path)?e.path.join("/"):e.path||"",a=Array.isArray(e.query)?e.query.filter(n=>n&&n.key).map(n=>`${encodeURIComponent(n.key)}=${encodeURIComponent(n.value||"")}`).join("&"):"",s=`${t}://${o}${r?`/${r}`:""}`;return a?`${s}?${a}`:s}function it(e){g.value=e.method||"GET",E.value=e.url||"",H.value=e.bodyMode||"none",ne.value=e.rawType||"json",N.value=e.bodyRaw||"",J.value=e.authType||"",F.value=e.authValue||"",K(Y,e.queryParams||[]),K(P,e.headers||[]),K(ee,e.formData||[]),K(te,e.urlEncoded||[]),K(oe,e.environment||[]),V(),ie()}function dt(){return{method:g.value,url:E.value.trim(),queryParams:L(Y),headers:L(P),bodyMode:H.value,rawType:ne.value,bodyRaw:N.value,formData:L(ee),urlEncoded:L(te),authType:J.value,authValue:F.value,environment:L(oe)}}function le(){return{method:"GET",url:"",queryParams:[],headers:[{key:"Accept",value:"application/json",enabled:!0},{key:"Content-Type",value:"application/json",enabled:!1},{key:"Authorization",value:"Bearer {{token}}",enabled:!1},{key:"X-API-Key",value:"{{api_key}}",enabled:!1},{key:"User-Agent",value:"ConversionTab-ApiTester/1.0",enabled:!1},{key:"Cache-Control",value:"no-cache",enabled:!1}],bodyMode:"raw",rawType:"json",bodyRaw:"",formData:[],urlEncoded:[],authType:"",authValue:"",environment:[]}}function Ce(e){for(const t of h)for(const o of t.modules){const r=o.requests.find(a=>a.id===e);if(r)return{collection:t,module:o,request:r}}return null}function ce(){const e=Ce(x);e&&(e.request.state=dt(),(!e.request.name||e.request.name.startsWith("New Request"))&&(e.request.name=(e.request.state.url||e.request.name||"Untitled Request").slice(0,48)))}function fe(e){const t=Ce(e);t&&(D=t.collection.id,re=t.module.id,x=e,it(t.request.state),M())}function z(e="Collection"){const t=`col_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;return h.push({id:t,name:e,collapsed:!1,modules:[]}),D=t,t}function W(e="Module",t=""){const o=`mod_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;let r=h.find(a=>a.id===t)||h.find(a=>a.id===D)||h[0];if(!r){const a=z("Default Collection");r=h.find(s=>s.id===a)}return r.modules.push({id:o,name:e,collapsed:!1,requests:[]}),D=r.id,re=o,o}function G(e=null,t="",o=""){ce();const r=`req_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;let s=h.flatMap(c=>c.modules).find(c=>c.id===o)||h.flatMap(c=>c.modules).find(c=>c.id===re)||h.flatMap(c=>c.modules)[0];if(!s){const c=W("Default Module",D);s=h.flatMap(l=>l.modules).find(l=>l.id===c)}s.requests.push({id:r,name:t||`New Request ${tt++}`,state:e||le()});const n=h.find(c=>c.modules.some(l=>l.id===s.id));n&&(D=n.id),re=s.id,fe(r)}function ye(e,t,o){const r=document.createElement("input");r.type="text",r.className="form-control form-control-sm",r.value=t;const a=e.parentElement;if(!a)return;a.replaceChild(r,e),r.focus(),r.select();const s=n=>{const c=r.value.trim();n&&c&&o(c),M()};r.addEventListener("blur",()=>s(!0)),r.addEventListener("keydown",n=>{n.key==="Enter"&&s(!0),n.key==="Escape"&&s(!1)})}function M(){we.innerHTML="",Ae.innerHTML="";const e=new Set(_);h.forEach(t=>{const o=document.createElement("div");o.className="mb-2 border rounded";const r=document.createElement("div");if(r.className="d-flex justify-content-between align-items-center p-2 bg-body",r.innerHTML=`<button type="button" class="btn btn-sm btn-link text-decoration-none p-0 fw-semibold" data-role="toggle-col">${t.collapsed?"▸":"▾"} ${t.name}</button><button type="button" class="btn btn-outline-secondary btn-sm" data-role="new-request">+ API</button>`,r.querySelector('[data-role="toggle-col"]').addEventListener("click",()=>{t.collapsed=!t.collapsed,M()}),r.querySelector('[data-role="new-request"]').addEventListener("click",()=>{const a=t.modules[0]||null;if(!a){const s=W("Default",t.id);G(null,"",s);return}G(null,"",a.id),M()}),r.querySelector('[data-role="toggle-col"]').addEventListener("dblclick",a=>{a.preventDefault();const s=r.querySelector('[data-role="toggle-col"]');ye(s,t.name,n=>{t.name=n})}),o.appendChild(r),!t.collapsed){const a=document.createElement("div");
8a.className="list-group list-group-flush",t.modules.forEach(s=>s.requests.forEach(n=>{const c=n.id===x,l=document.createElement("button");if(l.type="button",l.className=`list-group-item list-group-item-action text-start ${c?"active":""}`,l.innerHTML=`<span class="fw-semibold ct-req-title">${n.name||"Untitled Request"}</span><span class="small text-body-secondary ct-req-preview">${n.state.method||"GET"} ${n.state.url||""}</span>`,l.addEventListener("click",()=>{ce(),fe(n.id)}),l.addEventListener("dblclick",()=>{const d=l.querySelector(".fw-semibold");ye(d,n.name||"Request",f=>{n.name=f})}),a.appendChild(l),e.has(n.id)){const d=document.createElement("li");d.className="nav-item",d.role="presentation",d.innerHTML=`
9                            <button type="button" class="nav-link ${c?"active":""} ct-tab-btn" title="${s.name}">
10                                <span class="text-truncate">${n.name||"Untitled"}</span>
11                                <span class="ct-tab-close" data-role="close" title="Close">×</span>
12                            </button>
13                        `,d.querySelector("button").addEventListener("click",f=>{var R;if(((R=f.target)==null?void 0:R.getAttribute("data-role"))==="close"){f.preventDefault(),f.stopPropagation(),_=_.filter(i=>i!==n.id),M();return}ce(),fe(n.id)}),d.querySelector("button").addEventListener("dblclick",()=>{const f=d.querySelector(".text-truncate");ye(f,n.name||"Request",R=>{n.name=R})}),Ae.appendChild(d)}})),o.appendChild(a)}we.appendChild(o)})}function xe(e){var o,r;const t=JSON.parse(e);if((t==null?void 0:t.format)==="ct-api-collection/v1"){if(Array.isArray(t.collections)&&t.collections.length)return t.collections.map((a,s)=>({name:a.name||`Collection ${s+1}`,modules:Array.isArray(a.modules)?a.modules.map((n,c)=>({name:n.name||`Module ${c+1}`,requests:Array.isArray(n.requests)?n.requests.map((l,d)=>({name:l.name||`Request ${d+1}`,state:l.state||l})):[]})):[]}));if(Array.isArray(t.modules)&&t.modules.length)return[{name:"Imported Collection",modules:t.modules.map((a,s)=>({name:a.name||`Module ${s+1}`,requests:Array.isArray(a.requests)?a.requests.map((n,c)=>({name:n.name||`Request ${c+1}`,state:n.state||n})):[]}))}];if(t.request)return[{name:"Imported Collection",modules:[{name:"Imported Module",requests:[{name:"Imported Request",state:t.request}]}]}]}if((o=t==null?void 0:t.item)!=null&&o.length){const a=n=>{var l,d,f,R,i,p,A;const c=((l=n.body)==null?void 0:l.mode)||"none";return{method:n.method||"GET",url:ct(n.url),queryParams:Array.isArray((d=n.url)==null?void 0:d.query)?n.url.query.map(y=>({key:String(y.key||""),value:String(y.value||""),enabled:!y.disabled})):[],headers:Array.isArray(n.header)?n.header.map(y=>({key:String(y.key||""),value:String(y.value||""),enabled:!y.disabled})):[],bodyMode:c,rawType:c==="raw"?"json":"text",bodyRaw:((f=n.body)==null?void 0:f.raw)||"",formData:Array.isArray((R=n.body)==null?void 0:R.formdata)?n.body.formdata.map(y=>({key:String(y.key||""),value:String(y.value||""),enabled:!y.disabled})):[],urlEncoded:Array.isArray((i=n.body)==null?void 0:i.urlencoded)?n.body.urlencoded.map(y=>({key:String(y.key||""),value:String(y.value||""),enabled:!y.disabled})):[],authType:((p=n.auth)==null?void 0:p.type)==="bearer"?"bearer":((A=n.auth)==null?void 0:A.type)==="basic"?"basic":"",authValue:"",environment:[]}},s=[];return t.item.forEach((n,c)=>{if(Array.isArray(n.item))s.push({name:n.name||`Module ${c+1}`,requests:n.item.filter(l=>l==null?void 0:l.request).map((l,d)=>({name:l.name||`Request ${d+1}`,state:a(l.request)}))});else if(n!=null&&n.request){let l=s.find(d=>d.name==="Imported");l||(l={name:"Imported",requests:[]},s.push(l)),l.requests.push({name:n.name||`Request ${l.requests.length+1}`,state:a(n.request)})}}),[{name:((r=t.info)==null?void 0:r.name)||"Imported Collection",modules:s.filter(n=>n.requests.length)}]}throw new Error("Unsupported collection format")}function ut(){return ce(),{format:"ct-api-collection/v1",exportedAt:new Date().toISOString(),activeRequestId:x,collections:h.map(e=>({id:e.id,name:e.name,modules:e.modules.map(t=>({id:t.id,name:t.name,requests:t.requests.map(o=>({id:o.id,name:o.name,state:o.state}))}))}))}}function V(){const e=H.value,t=!["GET","HEAD"].includes(g.value),o=e!=="none";Fe.classList.toggle("d-none",!o||e!=="raw"),_e.classList.toggle("d-none",!o||e!=="raw"),Ke.classList.toggle("d-none",!o||e!=="form-data"),ze.classList.toggle("d-none",!o||e!=="x-www-form-urlencoded"),Ee&&(Ee.textContent=t?"Select a body type and enter request payload.":`${g.value} requests typically ignore request bodies in browsers.`)}function mt(e,t){if(!t.length)return e;const o=new URL(e);return t.forEach(({key:r,value:a})=>{o.searchParams.append(r,a)}),o.toString()}function ie(){const e=E.value.trim();if(!e){m.disabled=!0,$("");return}const t=Ue(e);if(!t.ok){m.disabled=!0,$(t.error);return}m.disabled=!1;const o=ke(t.url);if(!o){$("");return}if(o.fromRemotePageToLocalTarget){$(`Heads up: local/private API target (${o.parsed.host}) may be unreachable from this deployed site. If the request fails, run this tool locally or expose your API publicly.`);return}if(o.mixedContentRisk){$("Heads up: your page is HTTPS but the API URL is HTTP. Browsers usually block this mixed-content request.");return}$(""),V()}function pt(e){const t=String(e||"").split(";")[0].trim().toLowerCase();return t.startsWith("image/")?"image":t==="application/pdf"||t==="application/x-pdf"?"pdf":t==="text/html"||t==="application/xhtml+xml"?"html":"none"}function ft(e){const t=String(e||"").split(";")[0].trim().toLowerCase();return{"application/pdf":".pdf","image/png":".png","image/jpeg":".jpg","image/jpg":".jpg","image/gif":".gif","image/svg+xml":".svg","image/webp":".webp","image/avif":".avif","text/html":".html","application/xhtml+xml":".xhtml","application/json":".json","text/plain":".txt"}[t]||".bin"}function yt(){q&&(URL.revokeObjectURL(q),q=""),b&&(b.removeAttribute("src"),b.classList.add("d-none")),w&&(w.removeAttribute("src"),w.classList.add("d-none"))}function de(e){const t=e==="raw";Be&&Be.classList.toggle("d-none",!t),Se&&Se.classList.toggle("d-none",t),j==null||j.classList.toggle("active",t),v==null||v.classList.toggle("active",!t)}function Te(){yt(),B="none",T=null,O="application/octet-stream",v&&(v.disabled=!0),de("raw")}function gt(){if(!T||B==="none"||q)return;const e=new Blob([T],{type:O||"application/octet-stream"});q=URL.createObjectURL(e),B==="image"?(b==null||b.setAttribute("src",q),b==null||b.classList.remove("d-none"),w==null||w.classList.add("d-none")):(w==null||w.setAttribute("src",q),w==null||w.classList.remove("d-none"),b==null||b.classList.add("d-none"))}He.addEventListener("click",()=>k(Y)),Ne.addEventListener("click",()=>{const e=he.value;if(!e){k(P);return}se(e,{Accept:"application/json","Content-Type":"application/json",Authorization:"Bearer {{token}}","X-API-Key":"{{api_key}}","User-Agent":"ConversionTab-ApiTester/1.0","Cache-Control":"no-cache"}[e]||""),he.value=""}),Je.addEventListener("click",()=>k(ee)),De.addEventListener("click",()=>k(te)),Oe.addEventListener("click",()=>k(oe)),We.addEventListener("click",()=>{try{const e=rt(je.value),t=Object.entries(e);if(!t.length){u("No headers found in JSON");return}t.forEach(([o,r])=>se(o,r)),u("Headers imported",!1)}catch(e){u((e==null?void 0:e.message)||"Invalid headers JSON")}}),Ve.addEventListener("click",()=>ae.click()),Qe.addEventListener("click",()=>{be.classList.toggle("d-none")}),Ye.addEventListener("click",()=>{try{const e=xe(Ze.value);h=[],e.forEach((t,o)=>{const r=z(t.name||`Collection ${o+1}`);
13(t.modules||[]).forEach((a,s)=>{const n=W(a.name||`Module ${s+1}`,r);(a.requests||[]).forEach((c,l)=>G(c.state||le(),c.name||`Request ${l+1}`,n))})}),u("Collection imported",!1),be.classList.add("d-none")}catch(e){u((e==null?void 0:e.message)||"Invalid collection JSON")}}),ae.addEventListener("change",async()=>{var t;const e=(t=ae.files)==null?void 0:t[0];if(e)try{const o=await e.text(),r=xe(o);h=[],r.forEach((a,s)=>{const n=z(a.name||`Collection ${s+1}`);(a.modules||[]).forEach((c,l)=>{const d=W(c.name||`Module ${l+1}`,n);(c.requests||[]).forEach((f,R)=>G(f.state||le(),f.name||`Request ${R+1}`,d))})}),u("Collection imported",!1)}catch(o){u((o==null?void 0:o.message)||"Invalid collection file")}finally{ae.value=""}}),Xe.addEventListener("click",()=>{const e=JSON.stringify(ut(),null,2),t=new Blob([e],{type:"application/json;charset=utf-8"}),o=document.createElement("a");o.href=URL.createObjectURL(t),o.download="api-collection.json",o.click(),URL.revokeObjectURL(o.href)}),Re.addEventListener("click",()=>{Le.classList.toggle("ct-explorer-collapsed");const e=Le.classList.contains("ct-explorer-collapsed");Re.textContent=e?"Show explorer":"Hide explorer"}),Ge.addEventListener("click",()=>{const e=N.value.trim();if(e)try{N.value=JSON.stringify(JSON.parse(e),null,2),u("JSON formatted",!1)}catch{u("Invalid JSON")}}),ve.addEventListener("change",async()=>{var t;const e=(t=ve.files)==null?void 0:t[0];if(e)try{const o=await e.text();N.value=o,H.value="raw",ne.value="json",V(),u("JSON imported",!1)}catch{u("Failed to read JSON file")}}),J.addEventListener("change",()=>{const e=J.value;if(e){if(e==="bearer"){se("Authorization",`Bearer ${F.value.trim()||"<token>"}`);return}if(e==="basic"){const t=F.value.trim()||"username:password";se("Authorization",`Basic ${btoa(t)}`)}}}),F.addEventListener("blur",()=>{J.value&&J.dispatchEvent(new Event("change"))}),g.addEventListener("change",V),H.addEventListener("change",V),E.addEventListener("input",ie),ie(),et.addEventListener("click",()=>{const e=z("New Collection");W("Default",e),M()});const ht=z("Main Collection"),Et=W("Default",ht),vt={...le(),url:Lt};G(vt,"Sample todo (JSONPlaceholder)",Et),m.addEventListener("click",async()=>{const e=st(),t=new Set,o=I(E.value.trim(),e,t);if(!o)return;const r=Ue(o);if(!r.ok){u(r.error),$(r.error);return}const a=L(Y).map(({key:i,value:p})=>({key:I(i,e,t),value:I(p,e,t)})),s=mt(r.url,a),n=Object.fromEntries(L(P).map(({key:i,value:p})=>[I(i,e,t),I(p,e,t)])),c=g.value,l=!["GET","HEAD"].includes(c),d=H.value;let f;try{if(l&&d==="raw"){const i=N.value;if(i.trim()){f=I(i,e,t);const p=ne.value;!n["Content-Type"]&&!n["content-type"]&&(p==="json"&&(n["Content-Type"]="application/json"),p==="xml"&&(n["Content-Type"]="application/xml"),p==="text"&&(n["Content-Type"]="text/plain"))}}else if(l&&d==="form-data"){const i=new FormData;L(ee).forEach(({key:p,value:A})=>{i.append(I(p,e,t),I(A,e,t))}),f=i,delete n["Content-Type"],delete n["content-type"]}else if(l&&d==="x-www-form-urlencoded"){const i=new URLSearchParams;L(te).forEach(({key:p,value:A})=>{i.append(I(p,e,t),I(A,e,t))}),f=i.toString(),!n["Content-Type"]&&!n["content-type"]&&(n["Content-Type"]="application/x-www-form-urlencoded;charset=UTF-8")}}catch(i){u(`Request setup error: ${(i==null?void 0:i.message)||String(i)}`);return}if(t.size){u(`Missing environment variables: ${Array.from(t).join(", ")}`);return}m.disabled=!0,m.textContent="Sending...",x&&!_.includes(x)&&(_.push(x),M()),S.value="",ge.textContent="",ue.textContent="Sending…",Q.disabled=!0,X.disabled=!0,Z.disabled=!0,Te();const R=performance.now();try{const i=await fetch(s,{method:c,headers:n,body:l?f:void 0}),p=Math.round(performance.now()-R),A=await i.arrayBuffer(),y=i.headers.get("content-type")||"";T=A,O=y.split(";")[0].trim()||"application/octet-stream",B=pt(O);const bt=new TextDecoder;let U;if(B==="image"||B==="pdf")U=`[Binary response: ${O} · ${(A.byteLength/1024).toFixed(2)} KB]
14
15Open Preview to render in the browser, or Download to save the file.`;else{try{U=bt.decode(new Uint8Array(A))}catch{U=""}if(y.includes("application/json"))try{U=JSON.stringify(JSON.parse(U),null,2)}catch{}}S.value=U;const qe={};
15i.headers.forEach((wt,At)=>{qe[At]=wt}),ge.textContent=JSON.stringify(qe,null,2),ue.textContent=`${i.status} ${i.statusText} · ${p} ms · ${(A.byteLength/1024).toFixed(2)} KB`;const $e=B==="image"||B==="pdf",Me=!!U;Q.disabled=$e||!Me,Z.disabled=$e||!Me,X.disabled=!A.byteLength,v&&(v.disabled=B==="none"),de("raw"),u("Request completed",!1)}catch(i){Te(),ue.textContent="";const p=at(s);S.value=`${p}
16
17Original error: ${(i==null?void 0:i.message)||String(i)}`,Q.disabled=!S.value.trim(),Z.disabled=!0,X.disabled=!0,u(p)}finally{ie(),m.textContent=Pe}}),Q.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(S.value),u("Copied",!1)}catch{u("Copy failed")}}),X.addEventListener("click",()=>{const t=String((me==null?void 0:me.value)||"").trim().replace(/[\\/:*?"<>|]+/g,"_"),o=(O||"text/plain").split(";")[0].trim(),r=T?ft(o):".txt",a=t||"response",n=/\.[a-z0-9]{2,8}$/i.test(a)?a:`${a}${r}`,c=T?new Blob([T],{type:o||"application/octet-stream"}):new Blob([S.value],{type:"text/plain;charset=utf-8"}),l=document.createElement("a");l.href=URL.createObjectURL(c),l.download=n,l.click(),URL.revokeObjectURL(l.href)}),j==null||j.addEventListener("click",()=>de("raw")),v==null||v.addEventListener("click",()=>{v!=null&&v.disabled||(gt(),de("preview"))}),Z.addEventListener("click",()=>{const e=S.value.trim();if(e)try{S.value=JSON.stringify(JSON.parse(e),null,2),u("Response formatted",!1)}catch{u("Response is not valid JSON")}})}export{St as initApiTesterPage};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.