diff --git a/Extensions/combined/ryd.content-script.js b/Extensions/combined/ryd.content-script.js index 16da821..ac788eb 100644 --- a/Extensions/combined/ryd.content-script.js +++ b/Extensions/combined/ryd.content-script.js @@ -16,7 +16,7 @@ let isSetInitialStateDone = false; async function setEventListeners(evt) { async function checkForJS_Finish() { try { - if (isShorts() || (getButtons()?.offsetParent && isVideoLoaded())) { + if ((isShorts() && isVideoLoaded()) || (getButtons()?.offsetParent && isVideoLoaded())) { clearInterval(jsInitChecktimer); jsInitChecktimer = null; createSmartimationObserver(); diff --git a/Extensions/combined/src/utils.js b/Extensions/combined/src/utils.js index 2b09e3c..7d3c25a 100644 --- a/Extensions/combined/src/utils.js +++ b/Extensions/combined/src/utils.js @@ -1,4 +1,4 @@ -import { extConfig } from "./state"; +import { extConfig, isShorts } from "./state"; function numberFormat(numberState) { return getNumberFormatter(extConfig.numberDisplayFormat).format(numberState); @@ -91,8 +91,48 @@ function isInViewport(element) { ); } +function isShortsLoaded(videoId) { + if (!videoId) return false; + + // Find all reel containers + const reelContainers = document.querySelectorAll(".reel-video-in-sequence-new"); + + for (const container of reelContainers) { + // Check if this container's thumbnail matches our video ID + const thumbnail = container.querySelector(".reel-video-in-sequence-thumbnail"); + if (thumbnail) { + const bgImage = thumbnail.style.backgroundImage; + // YouTube thumbnail URLs contain the video ID in the format: /vi/VIDEO_ID/ + if ((bgImage && bgImage.includes(`/${videoId}/`)) || (!bgImage && isInViewport(container))) { + // Check if this container has the renderer with visible experiment-overlay + const renderer = container.querySelector("ytd-reel-video-renderer"); + if (renderer) { + const experimentOverlay = renderer.querySelector("#experiment-overlay"); + if ( + experimentOverlay && + !experimentOverlay.hidden && + window.getComputedStyle(experimentOverlay).display !== "none" && + experimentOverlay.hasChildNodes() + ) { + return true; + } + } + } + } + } + + return false; +} + function isVideoLoaded() { const videoId = getVideoId(window.location.href); + + // Check if this is a Shorts URL + if (isShorts()) { + return isShortsLoaded(videoId); + } + + // Regular video checks return ( // desktop: spring 2024 UI document.querySelector(`ytd-watch-grid[video-id='${videoId}']`) !== null || diff --git a/package.json b/package.json index 30aefc6..f788b27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "return-youtube-dislike", - "version": "3.0.0-18", + "version": "3.0.0-19", "description": "Chrome extension to return youtube dislikes", "main": "ryd.content-script.js", "scripts": {