Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
hung319 authored Jan 14, 2025
1 parent 7ea57fc commit ecb6148
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,32 @@ <h1>Tải ảnh NSFW</h1>
};

const fetchImage = async (retryCount = 3) => {
const selectedApi = document.getElementById('apiSelector').value;
const apiUrl = API_URLS[selectedApi];
try {
const response = await fetchWithRetry(apiUrl);
const data = await response.json();
const imageUrl = (selectedApi === 'waifu.pics' || selectedApi === 'nekosapi.com') ? data.url : data[0].file_url;
const imageResponse = await fetchWithRetry(imageUrl);
const imageBlob = await imageResponse.blob();
const fileName = imageUrl.split('/').pop();
return { imageBlob, fileName };
} catch (error) {
if (retryCount > 0) return fetchImage(retryCount - 1);
return null;
}
};
const selectedApi = document.getElementById('apiSelector').value;
const apiUrl = API_URLS[selectedApi];
try {
const response = await fetchWithRetry(apiUrl);
const data = await response.json();

let imageUrl;
if (selectedApi === 'waifu.pics') {
imageUrl = data.url;
} else if (selectedApi === 'nekosapi.com') {
imageUrl = data[0]?.url; // Lấy URL từ phần tử đầu tiên trong mảng
} else {
imageUrl = data[0]?.file_url;
}

if (!imageUrl) throw new Error("URL ảnh không xác định!");

const imageResponse = await fetchWithRetry(imageUrl);
const imageBlob = await imageResponse.blob();
const fileName = imageUrl.split('/').pop();
return { imageBlob, fileName };
} catch (error) {
if (retryCount > 0) return fetchImage(retryCount - 1);
return null;
}
};
const downloadImages = async (count) => {
const zip = new JSZip();
let completed = 0;
Expand Down

0 comments on commit ecb6148

Please sign in to comment.