From aca52abefc23c7c590843180cec3b9cf17f83b40 Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 28 Dec 2021 11:58:05 -0500 Subject: [PATCH] Make skip notice work on channel trailer --- src/utils.ts | 15 ++++++++++----- src/utils/pageUtils.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index bdb441e7..c5299b40 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,6 +2,7 @@ import Config from "./config"; import { CategorySelection, SponsorTime, FetchResponse, BackgroundScriptContainer, Registration } from "./types"; import * as CompileConfig from "../config.json"; +import { findValidElement } from "./utils/pageUtils"; export default class Utils { @@ -436,11 +437,15 @@ export default class Utils { } findReferenceNode(): HTMLElement { - let referenceNode = document.getElementById("player-container-id") - ?? document.getElementById("movie_player") - ?? document.querySelector("#main-panel.ytmusic-player-page") // YouTube music - ?? document.querySelector("#player-container .video-js") // Invidious - ?? document.querySelector(".main-video-section > .video-container"); // Cloudtube + const selectors = [ + "#player-container-id", + "#movie_player", + "#c4-player", // Channel Trailer + "#main-panel.ytmusic-player-page", // YouTube music + "#player-container .video-js", // Invidious + ".main-video-section > .video-container" // Cloudtube + ] + let referenceNode = findValidElement(selectors) if (referenceNode == null) { //for embeds const player = document.getElementById("player"); diff --git a/src/utils/pageUtils.ts b/src/utils/pageUtils.ts index e88f7cc9..d94b36d5 100644 --- a/src/utils/pageUtils.ts +++ b/src/utils/pageUtils.ts @@ -17,4 +17,19 @@ export function getControls(): HTMLElement | false { } return false; +} + +export function isVisible(element: HTMLElement): boolean { + return element.offsetWidth > 0 && element.offsetHeight > 0; +} + +export function findValidElement(selectors: string[]): HTMLElement { + for (const selector of selectors) { + const element = document.querySelector(selector) as HTMLElement; + if (element && isVisible(element)) { + return element; + } + } + + return null; } \ No newline at end of file