document.getElementById("currentYear").textContent=(new Date).getFullYear();const imageUrlInput=document.getElementById("imageUrl"),positionInput=document.getElementById("position"),fetchButton=document.getElementById("fetchButton"),buttonText=document.getElementById("buttonText"),loadingSpinner=document.getElementById("loadingSpinner"),outputDiv=document.getElementById("output"),errorDisplayDiv=document.getElementById("errorDisplay"),byteInspectorForm=document.getElementById("byteInspectorForm");async function fetchByteValue(){fetchButton.disabled=!0,buttonText.textContent="Fetching...",loadingSpinner.style.display="inline-block",outputDiv.style.display="none",outputDiv.innerHTML="",errorDisplayDiv.innerHTML="";const e=imageUrlInput.value,t=positionInput.value,n=parseInt(t);if(!e)return displayError("Please enter a URL."),void resetButton();if(isNaN(n)||n<1)return displayError("Please enter a valid byte position (starting at 1)."),void resetButton();try{const t=await fetch(e);if(!t.ok)throw new Error(`HTTP error! Status: ${t.status} ${t.statusText}`);const a=await t.arrayBuffer(),s=new Uint8Array(a),r=n-1;if(r>=s.length)return displayError(`Position ${n} exceeds file length (${s.length} bytes).`),void resetButton();const i=s[r],o=i.toString(16).padStart(2,"0").toUpperCase(),l=i,u=String.fromCharCode(i),p=`U+${o.padStart(4,"0")}`;outputDiv.innerHTML=`\n

Byte Information:

\n
\n
\n Hex Value:\n ${o}\n
\n
\n Decimal Value:\n ${l}\n
\n
\n Unicode Char:\n '${escapeHtml(u)}'\n
\n
\n Unicode Code Point:\n ${p}\n
\n
\n File Size:\n ${s.length.toLocaleString()} bytes\n
\n
\n `,outputDiv.style.display="block"}catch(e){console.error(e),displayError(`Error: ${e.message}. Ensure the URL is correct, publicly accessible, and allows CORS (Cross-Origin Resource Sharing). For local files, try using a simple HTTP server instead of file:/// URLs due to browser security restrictions.`)}finally{resetButton()}}function resetButton(){fetchButton.disabled=!1,buttonText.textContent="Fetch Byte Value",loadingSpinner.style.display="none"}function displayError(e){errorDisplayDiv.innerHTML=`

Error:

${e}

`}function escapeHtml(e){return null==e?"":e.toString().replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}byteInspectorForm.addEventListener("submit",(async function(e){e.preventDefault(),await fetchByteValue()}));