diff --git a/web.js b/web.js index a7213a7..8c4017d 100644 --- a/web.js +++ b/web.js @@ -1,55 +1 @@ -var modalel = document.createElement('div'); -modalel.innerHTML = ` - -`; -modalel.classList.add('modal'); -modalel.tabIndex = -1; -document.body.appendChild(modalel); -var fileinput = modalel.querySelector('#agentfile'); -var uploadbtn = modalel.querySelector('#agentUploadBtn'); -var successalert = modalel.querySelector('#agentSuccessAlert'); -var erroralert = modalel.querySelector('#agentErrorAlert'); -uploadbtn.addEventListener('click', async () => { - if (fileinput.files.length == 0) return; - successalert.style.display = 'none'; - erroralert.style.display = 'none'; - var file = fileinput.files[0]; - var result = await fetch(`https://vmup.elijahr.dev/${window.VMName}/${file.name}`, { - method: 'PUT', - body: file, - headers: { - 'Content-Type': 'application/octet-stream' - } - }); - var json = await result.json(); - if (json.success) { - successalert.style.display = 'block'; - successalert.innerText = json.result; - } else { - erroralert.style.display = 'block'; - erroralert.innerText = json.result; - } -}); -var modal = new bootstrap.Modal(modalel); -var btn = document.createElement('button'); -btn.innerHTML = ' Upload File'; -btn.classList.add('btn', 'btn-secondary'); -btn.addEventListener('click', () => { - modal.show(); -}); -document.getElementById('btns').appendChild(btn); \ No newline at end of file +if (window.uploadbuttonadded !== true) {window.uploadbuttonadded=true;var modalel=document.createElement('div');modalel.innerHTML=``;modalel.classList.add('modal');modalel.tabIndex=-1;document.body.appendChild(modalel);var fileinput=modalel.querySelector('#agentfile');var uploadbtn=modalel.querySelector('#agentUploadBtn');var successalert=modalel.querySelector('#agentSuccessAlert');var erroralert=modalel.querySelector('#agentErrorAlert');uploadbtn.addEventListener('click',async()=>{if(fileinput.files.length==0){return}successalert.style.display='none';erroralert.style.display='none';var file=fileinput.files[0];var result=await fetch(`https://vmup.elijahr.dev/${window.VMName || window.vmName }/${file.name }`,{method:'PUT',body:file,headers:{'Content-Type':'application/octet-stream'}});var json=await result.json();if(json.success){successalert.style.display='block';successalert.innerText=json.result}else{erroralert.style.display='block';erroralert.innerText=json.result}});var btn=document.createElement('button');btn.innerHTML=' Upload File';btn.classList.add('btn','btn-secondary');if (window.bootstrap !== undefined) { var modal = new bootstrap.Modal(modalel); btn.addEventListener('click',()=>{modal.show()});} else {btn.addEventListener('click',()=>{$(modalel).modal('show')});}document.getElementById('btns').appendChild(btn);}