function base64ToHex(t){try{t=t.replace(/_/g,"/").replace(/-/g,"+");const e=atob(t);return Array.from(e).map((t=>t.charCodeAt(0).toString(16).padStart(2,"0"))).join("")}catch(t){return null}}function autoConvertAndCopy(){const t=document.getElementById("json-input").value.trim(),e=document.getElementById("base64-input").value.trim();if(e){if(e.includes(":")){const[t,o]=e.split(":"),[n,u]=[t,o].map(base64ToHex);return document.getElementById("json-output").value=n&&u?n+":"+u:"Invalid Base64 input.",void(n&&u&&copyToClipboard())}const t=base64ToHex(e);if(t)return document.getElementById("json-output").value=t,void copyToClipboard()}if(t){let e;try{e=JSON.parse(t)}catch{return}const o=t=>{if(Array.isArray(t))return t.map(o);if("object"==typeof t&&t){if(t.kid&&t.k){const[e,o]=[t.kid,t.k].map(base64ToHex);return e&&o?e+":"+o:t}for(const e in t)t.hasOwnProperty(e)&&(t[e]=o(t[e]))}return t},n=o(e);n&&(document.getElementById("json-output").value=JSON.stringify(n,null,2),copyToClipboard())}}function copyToClipboard(){const t=document.getElementById("json-output");t.select(),navigator.clipboard.writeText(t.value).then((()=>{showCopySuccessPopup()})).catch((t=>{alert("Failed to copy: "+t)}))}function showCopySuccessPopup(){const t=document.createElement("div");t.classList.add("popup"),t.textContent="Copied successfully!",document.body.appendChild(t),setTimeout((()=>t.classList.add("show")),10),setTimeout((()=>{t.classList.remove("show"),setTimeout((()=>document.body.removeChild(t)),300)}),2e3)}function clearAllFields(){document.getElementById("json-input").value="",document.getElementById("json-output").value="",document.getElementById("base64-input").value=""}function pasteFromClipboard(t){navigator.clipboard.readText().then((e=>{document.getElementById(t).value=e,autoConvertAndCopy()})).catch((t=>{alert("Failed to read clipboard contents: "+t)}))}