Skip to content

Commit

Permalink
Made the code scalable to add infinite amounts of MrBeasts by checkin…
Browse files Browse the repository at this point in the history
…g the existance of MrBeastImages every startup
  • Loading branch information
MagicJinn committed Jul 3, 2023
1 parent c34ea5e commit a587d14
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 53 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"run_at": "document_idle"
}],
"web_accessible_resources": [
"images/1.png", "images/2.png", "images/3.png", "images/4.png", "images/5.png", "images/6.png", "images/7.png", "images/8.png", "images/9.png", "images/10.png", "images/11.png", "images/12.png", "images/13.png", "images/14.png", "images/15.png", "images/16.png", "images/17.png", "images/18.png", "images/19.png", "images/20.png", "images/21.png", "images/22.png", "images/23.png", "images/24.png", "images/25.png", "images/26.png", "images/27.png", "images/28.png", "images/29.png", "images/30.png", "images/31.png"
"images/*.png"
]
}
83 changes: 31 additions & 52 deletions mrbeastify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const imagesPath = "images/";
const images = [];

// Apply the overlay
function applyOverlay(thumbnailElement, overlayImageUrl, flip) {
Expand All @@ -24,17 +25,17 @@ function applyOverlay(thumbnailElement, overlayImageUrl, flip) {
thumbnailElement.classList.add("processed");
}

// looks for all thumbnails and applies overlay
// Looks for all thumbnails and applies overlay
function applyOverlayToThumbnails() {
// Query all YouTube video thumbnails on the page that haven"t been processed yet, and also ignores shorts thumbnails
// Query all YouTube video thumbnails on the page that haven't been processed yet, and also ignores shorts thumbnails
const elementQuery =
"ytd-thumbnail:not(.ytd-rich-grid-slim-media) > a > yt-image > img.yt-core-image:not(.processed):not(.yt-core-attributed-string__image-element)";
const thumbnailElements = document.querySelectorAll(elementQuery);

// Apply overlay to each thumbnail
thumbnailElements.forEach((thumbnailElement) => {
// Apply overlay and add to processed thumbnails
let loops = Math.random() > 0.001 ? 1 : 20;
let loops = Math.random() > 0.001 ? 1 : 20; // Easter egg
for (let i = 0; i < loops; i++) {
// Get overlay image URL from your directory
const overlayImageUrl = getRandomImageFromDirectory();
Expand All @@ -44,61 +45,39 @@ function applyOverlayToThumbnails() {
});
}

function checkImageAmountInDirectory() { // Checks for all images in the images folder instead of using a preset array, making the extension infinitely scalable
let imageIndex = 1;
function checkImageExistence() {
const testedURL = chrome.runtime.getURL(`${imagesPath}${imageIndex}.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
imageIndex++;
checkImageExistence();
} else {
throw new Error("Image not found");
}
})
.catch(error => {
// Stop checking for new images
console.log("Total MrBeast images found:", images.length);
});
}
checkImageExistence();
}

// Get a random image URL from a directory
function getRandomImageFromDirectory() {
const images = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
];
const randomIndex = Math.floor(Math.random() * images.length);
if (
typeof chrome !== "undefined" &&
chrome.runtime &&
chrome.runtime.getURL
) {
// Chrome or Edge
return chrome.runtime.getURL(`${imagesPath}${images[randomIndex]}.png`);
} else if (
typeof browser !== "undefined" &&
browser.extension &&
browser.extension.getURL
) {
// Firefox
return browser.extension.getURL(`${imagesPath}${images[randomIndex]}`);
}
return images[randomIndex];
}

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

console.log("MrBeastify Loaded Successfully");
console.log("MrBeastify Loaded Successfully");

0 comments on commit a587d14

Please sign in to comment.