Something went wrong. Try again.
forked from denzha24/kumify
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889"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)) ); }})();