document.getElementById('currentYear').textContent = new Date().getFullYear(); const imageUrlInput = document.getElementById('imageUrl'); const positionInput = document.getElementById('position'); const fetchButton = document.getElementById('fetchButton'); const buttonText = document.getElementById('buttonText'); const loadingSpinner = document.getElementById('loadingSpinner'); const outputDiv = document.getElementById('output'); const errorDisplayDiv = document.getElementById('errorDisplay'); const byteInspectorForm = document.getElementById('byteInspectorForm'); byteInspectorForm.addEventListener('submit', async function(event) { event.preventDefault(); await fetchByteValue(); }); async function fetchByteValue() { fetchButton.disabled = true; buttonText.textContent = 'Fetching...'; loadingSpinner.style.display = 'inline-block'; outputDiv.style.display = 'none'; outputDiv.innerHTML = ''; errorDisplayDiv.innerHTML = ''; const url = imageUrlInput.value; const positionStr = positionInput.value; const position = parseInt(positionStr); if (!url) { displayError('Please enter a URL.'); resetButton(); return; } if (isNaN(position) || position < 1) { displayError('Please enter a valid byte position (starting at 1).'); resetButton(); return; } try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status} ${response.statusText}`); } const buffer = await response.arrayBuffer(); const byteArray = new Uint8Array(buffer); const zeroBasedIndex = position - 1; if (zeroBasedIndex >= byteArray.length) { displayError(`Position ${position} exceeds file length (${byteArray.length} bytes).`); resetButton(); return; } const targetByte = byteArray[zeroBasedIndex]; const hexValue = targetByte.toString(16).padStart(2, '0').toUpperCase(); const decimalValue = targetByte; const unicodeChar = String.fromCharCode(targetByte); const unicodeCodePoint = `U+${hexValue.padStart(4, '0')}`; outputDiv.innerHTML = `