Skip to content

Commit

Permalink
improved script
Browse files Browse the repository at this point in the history
  • Loading branch information
shailendramaurya committed Oct 10, 2023
1 parent aa5d375 commit 117c7c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<link rel="icon" type="image/png" href="logo.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico/css/pico.classless.min.css">
<link rel="stylesheet" href="https://css.gg/css?=website|loadbar-alt|check">
<link rel="stylesheet" href="https://css.gg/css?=website|loadbar-alt|check|info">
<link rel="stylesheet" href="racoon.css">
<script src="modal.js" type="text/javascript" async></script>
<script src="index.js" async></script>
Expand Down
30 changes: 24 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ const status = {
statusDiv.innerHTML=``;
statusDiv.innerHTML=`
<i class="gg-check"></i><br><h4>`+fileSize+`</h4>`;
},
"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";
Expand Down Expand Up @@ -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);
});
}
5 changes: 3 additions & 2 deletions racoon.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 117c7c8

Please sign in to comment.