From 117c7c8d8e11f7e0301b9ed96ccdefa0413beefa Mon Sep 17 00:00:00 2001 From: "shailendramaurya.in@gmail.com" Date: Tue, 10 Oct 2023 16:26:58 +0530 Subject: [PATCH] improved script --- index.html | 2 +- index.js | 30 ++++++++++++++++++++++++------ racoon.css | 5 +++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 3528e5b..b6a96bd 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ - + diff --git a/index.js b/index.js index 228e545..ff6f314 100644 --- a/index.js +++ b/index.js @@ -15,18 +15,27 @@ const status = { statusDiv.innerHTML=``; statusDiv.innerHTML=`

`+fileSize+`

`; + }, + "error": function(msg){ + statusDiv.innerHTML=``; + statusDiv.innerHTML=msg; } } function processUrl(x){ if(url){ document.getElementById('url').value=url; + if(ref=='ytify'){ + document.getElementById('isAudioOnly').checked=true; + submit(x); + } submit(x); } else{return} } processUrl(url); + function submit(x) { if(!x){return} var api = "https://co.wuk.sh/api/json"; @@ -57,36 +66,45 @@ status.loading(); fetch(api, requestOptions) .then(response => { if (!response.ok) { - throw new Error('Network response was not ok'); + status.error('Network response was not ok'); } return response.json(); }) .then(data => { console.log('Response data:', data); - + if(data.status=='error'){ + status.error(data.text); + return; + } + else if(data.status=='redirect'){ + window.open(data.url,'_blank'); + status.success('Redirected'); + return; + } + const fileUrl = data.url; // Fetch the file size fetch(fileUrl) .then(response => { if (!response.ok) { - throw new Error('File download failed'); + status.error('File download failed'); } return response.headers.get('content-length'); }) .then(fileSize => { status.success(formatBytes(fileSize)); - // create a download link +// create a download link const downloadLink = document.createElement('a'); downloadLink.href = fileUrl; downloadLink.download = 'file'; downloadLink.click(); }) .catch(error => { - console.error('Error downloading file:', error); + status.error('Error downloading file:', error); }); }) .catch(error => { - console.error('Error:', error); + status.error(error); }); } \ No newline at end of file diff --git a/racoon.css b/racoon.css index dd66bf6..87c725f 100644 --- a/racoon.css +++ b/racoon.css @@ -98,10 +98,11 @@ figure img { } #status{ display:flex; - position:fixed; + position:absolute; + margin:15px; left:50%; top:50%; - transform:translate(-50%,-50%); + transform:translate(-50%,-40%); } #status i{ scale:4;