From da193d34517aa63d5a1b96786873fb4346d36f46 Mon Sep 17 00:00:00 2001 From: yash Date: Sun, 19 Jul 2026 21:17:04 +0300 Subject: [PATCH] init --- content.js | 68 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/content.js b/content.js index 8005c5b..adb5d9c 100644 --- a/content.js +++ b/content.js @@ -15,6 +15,9 @@ const PLAY_INDICATOR_SELECTOR = ".VibeResetButton_root__ju8pE"; let container = null; let currentEl = null; +const videoCache = {}; +const imgCache = {}; + function random(arr) { return arr[Math.floor(Math.random() * arr.length)]; } @@ -23,27 +26,62 @@ function elStyle(width, height) { return `display:block;width:${width}px;height:${height}px;object-fit:cover;pointer-events:none;z-index:0;position:relative;`; } +function wrapWithEdgeBlur(mediaEl, width, height) { + const wrapper = document.createElement("div"); + wrapper.style.cssText = ` + position:relative;width:${width}px;height:${height}px;overflow:hidden;border-radius:20px; + mask-image: + linear-gradient(to right, transparent 0%, black 12%, black 88%, transparent 100%), + linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%); + mask-composite:intersect; + -webkit-mask-image: + linear-gradient(to right, transparent 0%, black 12%, black 88%, transparent 100%), + linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%); + -webkit-mask-composite:destination-in; + `; + + wrapper.appendChild(mediaEl); + return wrapper; +} + +function getOrCreateImg(src, width, height) { + if (!imgCache[src]) { + const img = document.createElement("img"); + img.src = src; + img.style.cssText = elStyle(width, height); + imgCache[src] = img; + } + return imgCache[src]; +} + +function getOrCreateVideo(src, width, height) { + if (!videoCache[src]) { + const video = document.createElement("video"); + video.src = src; + video.setAttribute("autoplay", ""); + video.setAttribute("loop", ""); + video.setAttribute("muted", ""); + video.setAttribute("playsinline", ""); + video.setAttribute("preload", "auto"); + video.muted = true; + video.style.cssText = elStyle(width, height); + videoCache[src] = video; + } + return videoCache[src]; +} + function showPhoto(width, height) { - const img = document.createElement("img"); - img.src = random(PHOTOS); - img.style.cssText = elStyle(width, height); + const img = getOrCreateImg(random(PHOTOS), width, height); currentEl?.remove(); - currentEl = img; - container.appendChild(img); + currentEl = wrapWithEdgeBlur(img, width, height); + container.appendChild(currentEl); } function showVideo(width, height) { - const video = document.createElement("video"); - video.src = random(VIDEOS); - video.setAttribute("autoplay", ""); - video.setAttribute("loop", ""); - video.setAttribute("muted", ""); - video.setAttribute("playsinline", ""); - video.muted = true; - video.style.cssText = elStyle(width, height); + const video = getOrCreateVideo(random(VIDEOS), width, height); currentEl?.remove(); - currentEl = video; - container.appendChild(video); + currentEl = wrapWithEdgeBlur(video, width, height); + container.appendChild(currentEl); video.play().catch(() => {}); }