Skip to content

Commit

Permalink
Merge branch 'delay-checkImageExistence'
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicJinn committed Jul 4, 2023
2 parents 6ccb604 + 1ceb73b commit 9867ff4
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions mrbeastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,27 @@ function applyOverlayToThumbnails() {
});
}

function checkImageExistence(index) {
function checkImageExistence(index = 1) { // Checks for all images in the images folder instead of using a preset array, making the extension infinitely scalable
const testedURL = chrome.runtime.getURL(`${imagesPath}${index}.png`);
fetch(testedURL).then((response) => {
fetch(testedURL).then(response => {
if (response.status === 200) {
// Image exists, add it to the images array
images.push(testedURL);
// Check the next image in the directory
checkImageExistence(index + 1);
}
}).catch(error => {
setInterval(applyOverlayToThumbnails, 100);
console.log("MrBeastify Loaded Successfully, " + (index - 1) + " images detected.");
});
}


checkImageExistence();


// Get a random image URL from a directory
function getRandomImageFromDirectory() {
const randomIndex = Math.floor(Math.random() * images.length);
return images[randomIndex];
}

// Checks for all images in the images folder instead of using a preset array, making the extension infinitely scalable
let imageIndex = 1;
checkImageExistence(imageIndex);

setInterval(function () {
applyOverlayToThumbnails();
}, 100);

console.log("MrBeastify Loaded Successfully");

0 comments on commit 9867ff4

Please sign in to comment.