From 48c2b9ed47a641f1d4e0df0a8c8557b6c9ab5f5b Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 5 Jul 2023 20:30:30 +0800 Subject: [PATCH 1/2] fix: refresh page by clicking on youtube logo now renders new images --- mrbeastify.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/mrbeastify.js b/mrbeastify.js index 9dedf66..1f46b7f 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,25 +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) { - // 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."); - }); + 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); From 5abe3e1bfd3daf224fb8e1991ec169cebd755604 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Wed, 5 Jul 2023 15:25:04 +0200 Subject: [PATCH 2/2] removed unnecessary if statement --- mrbeastify.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mrbeastify.js b/mrbeastify.js index 1f46b7f..c3bd8b2 100644 --- a/mrbeastify.js +++ b/mrbeastify.js @@ -51,12 +51,10 @@ function checkImageExistence(index = 1) { const testedURL = chrome.runtime.getURL(`${imagesPath}${index}.png`); 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); - } + // 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); @@ -72,4 +70,4 @@ checkImageExistence(); function getRandomImageFromDirectory() { const randomIndex = Math.floor(Math.random() * images.length); return images[randomIndex]; -} +} \ No newline at end of file