Skip to content

Commit

Permalink
Merge pull request #17 from ryantanrk/fix-refresh
Browse files Browse the repository at this point in the history
fix: refresh page by clicking on youtube logo now renders new images
  • Loading branch information
MagicJinn authored Jul 5, 2023
2 parents 9867ff4 + 5abe3e1 commit 832a5db
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions mrbeastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ 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
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
Expand All @@ -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];
}
}

0 comments on commit 832a5db

Please sign in to comment.