"use strict"; (() => { const NUM_IMAGES = 131; const NUM_GIFS = 4; const THUMBNAIL_SELECTOR = 'img[src*="ytimg.com"]'; const SHORTS_SELECTORS = [ "ytm-shorts-lockup-view-model", "ytm-shorts-lockup-view-model-v2", ]; chrome.storage.local.get( ["overlayEnabled", "imagesEnabled", "gifsEnabled"], (prefs) => { const enabled = prefs.overlayEnabled !== false; const imagesOn = prefs.imagesEnabled !== false; const gifsOn = prefs.gifsEnabled !== false; if (!enabled || (!imagesOn && !gifsOn)) return; const pickOverlayUrl = buildPicker(imagesOn, gifsOn); const processPage = () => applyOverlays(pickOverlayUrl, enabled); processPage(); new MutationObserver(processPage).observe(document.body, { childList: true, subtree: true, }); }, ); function buildPicker(imagesOn, gifsOn) { const total = (imagesOn ? NUM_IMAGES : 0) + (gifsOn ? NUM_GIFS : 0); return () => { const roll = Math.floor(Math.random() * total); if (imagesOn && roll < NUM_IMAGES) { const i = Math.floor(Math.random() * NUM_IMAGES) + 1; return chrome.runtime.getURL(`assets/images/${i}.png`); } const i = Math.floor(Math.random() * NUM_GIFS) + 1; return chrome.runtime.getURL(`assets/gifs/${i}.gif`); }; } function applyOverlays(pickUrl, enabled) { const thumbnails = document.querySelectorAll(THUMBNAIL_SELECTOR); for (const thumb of thumbnails) { if (thumb.dataset.kumifyOverlay) continue; if (isShorts(thumb)) continue; const parent = thumb.parentElement; if (!parent) continue; if (getComputedStyle(parent).position === "static") { parent.style.position = "relative"; } const overlay = document.createElement("img"); overlay.src = pickUrl(); Object.assign(overlay.style, { position: "absolute", inset: "0", width: "100%", height: "100%", zIndex: "9999", pointerEvents: "none", objectFit: "cover", opacity: enabled ? "1" : "0", }); parent.appendChild(overlay); thumb.dataset.kumifyOverlay = "true"; } } function isShorts(img) { return ( img.classList.contains("shortsLockupViewModelHostThumbnail") || SHORTS_SELECTORS.some((sel) => img.closest(sel)) ); } })();