diff --git a/mrbeastify.js b/mrbeastify.js index 9dedf66..c3bd8b2 100644 --- a/mrbeastify.js +++ b/mrbeastify.js @@ -22,7 +22,6 @@ function applyOverlay(thumbnailElement, overlayImageUrl, flip) { // Append the overlay to the parent of the thumbnail thumbnailElement.parentElement.appendChild(overlayImage); - thumbnailElement.classList.add("processed"); } // Looks for all thumbnails and applies overlay @@ -30,7 +29,7 @@ function applyOverlayToThumbnails() { // Query all YouTube video thumbnails on the page that haven't been processed yet // (ignores shorts thumbnails) const elementQuery = - "ytd-thumbnail:not(.ytd-video-preview, .ytd-rich-grid-slim-media) a > yt-image > img.yt-core-image:not(.processed):not(.yt-core-attributed-string__image-element)"; + "ytd-thumbnail:not(.ytd-video-preview, .ytd-rich-grid-slim-media) a > yt-image > img.yt-core-image:only-child:not(.yt-core-attributed-string__image-element)"; const thumbnailElements = document.querySelectorAll(elementQuery); // Apply overlay to each thumbnail @@ -47,27 +46,28 @@ function applyOverlayToThumbnails() { }); } -function checkImageExistence(index = 1) { // Checks for all images in the images folder instead of using a preset array, making the extension infinitely scalable +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 => { - if (response.status === 200) { + fetch(testedURL) + .then((response) => { // 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."); - }); + }) + .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]; -} +} \ No newline at end of file