function l(U){return document.getElementById(U)} function r(){l("upload-area").style.display="none";l("conversion-area").style.display="block"} var z=Date.now();function p(){const u=l("file-input");const i=l("conversion-options").value;if(!u.files.length||!i){alert("Please select a file and conversion option.");return} const O=u.files[0];const B=new FormData();B.append('file',O);B.append('conversion_option',i);const S=new XMLHttpRequest();S.open('POST','convert.php');S.upload.addEventListener('progress',function(I){const k=l('progress-bar-fill');const G=(I.loaded/I.total)*100;k.style.width=G+'%'});S.responseType='blob';S.onreadystatechange=function(){if(S.readyState==2){if(S.status==200){S.responseType="blob"}else{S.responseType="text"}} if(S.readyState===XMLHttpRequest.DONE){if(S.status===200){const R=S.response;const T=URL.createObjectURL(R);const W=document.createElement('a');W.href=T;const C=O.name.split(".")[0]+"."+i.toLowerCase();W.download=C;document.body.appendChild(W);W.click();document.body.removeChild(W);URL.revokeObjectURL(T)}else{const q=S.getResponseHeader("Content-Type");if(q.includes("application/json")){const D=JSON.parse(S.responseText);alert("Error: "+D.message)}else{alert('Error occurred during file conversion.')}}}};S.send(B)} let g={};function b(){return fetch('options.json?'+z).then(D=>D.json()).then(M=>{g=M;return g})} b() function f(N){if(N.toLowerCase()=="webp"){return"WebP"} return N.toUpperCase()} function d(){r();var u=l("file-input");var h=l("conversion-options");var O=u.files[0];var m=j(O.name);var c=g;h.innerHTML="";if(m!=window.options[1]){document.getElementsByTagName("h1")[0].innerText=f(m)+" Converter"} if(m&&c[m]){c[m].forEach(H=>{var n=document.createElement("option");n.value=H;n.textContent=H.toUpperCase();h.appendChild(n);if(window.options[1]==H){document.getElementById("conversion-options").value=H}})}else{var n=document.createElement("option");n.textContent="No conversion options available";n.disabled=!0;h.appendChild(n)}} function j(C){return C.split('.').pop().toLowerCase()} document.getElementById("convert-btn").onclick=p;document.getElementById("file-input").onchange=d;var v=document.querySelectorAll('.dropdown');v.forEach(function(A){A.addEventListener('mouseenter',function(){this.classList.add('active')});A.addEventListener('click',function(I){this.classList.add('active');I.stopPropagation()});A.addEventListener('mouseleave',function(){this.classList.remove('active')})});document.addEventListener('click',function(I){v.forEach(function(A){if(!A.contains(I.target)){A.classList.remove('active')}})});var s=document.querySelectorAll('.dropdown2');s.forEach(function(A){A.addEventListener('click',function(){var F=this.classList;var w=F[F.length-1];var e=document.querySelectorAll('[category="'+w+'"]');var V=0;if(this.innerText.charAt(0)==String.fromCharCode(9658)){this.innerText=String.fromCharCode(9660)+this.innerText.slice(1)}else{this.innerText=String.fromCharCode(9658)+this.innerText.slice(1)} e.forEach(function(E){V++;setTimeout(function(){E.classList.toggle("active")},V*10)})})});var K=new Image();K.src="/logo.svg";var L=new Image();L.src="/logo2.svg";function y(){var t="/logo.svg";var P=document.getElementsByClassName("logo")[0];if(parseFloat(window.getComputedStyle(P,null).getPropertyValue('width'))==20){t="/logo2.svg"} if(!P.src.includes(t)){P.src=t}} window.addEventListener('resize',y);y()