mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 03:57:09 +03:00
Fix thumbnails not displaying full video labels on new YouTube layout
Fixes #2332
This commit is contained in:
Submodule maze-utils updated: 2c6822ec85...57038b5b54
@@ -1,9 +1,10 @@
|
|||||||
import { isOnInvidious, parseYouTubeVideoIDFromURL } from "../../maze-utils/src/video";
|
import { extractVideoID, isOnInvidious } from "../../maze-utils/src/video";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { getHasStartSegment, getVideoLabel } from "./videoLabels";
|
import { getHasStartSegment, getVideoLabel } from "./videoLabels";
|
||||||
import { getThumbnailSelector, setThumbnailListener } from "../../maze-utils/src/thumbnailManagement";
|
import { getThumbnailSelector, setThumbnailListener } from "../../maze-utils/src/thumbnailManagement";
|
||||||
import { VideoID } from "../types";
|
import { VideoID } from "../types";
|
||||||
import { getSegmentsForVideo } from "./segmentData";
|
import { getSegmentsForVideo } from "./segmentData";
|
||||||
|
import { onMobile } from "../../maze-utils/src/pageInfo";
|
||||||
|
|
||||||
export async function handleThumbnails(thumbnails: HTMLImageElement[]): Promise<void> {
|
export async function handleThumbnails(thumbnails: HTMLImageElement[]): Promise<void> {
|
||||||
await Promise.all(thumbnails.map((t) => {
|
await Promise.all(thumbnails.map((t) => {
|
||||||
@@ -18,7 +19,7 @@ export async function labelThumbnail(thumbnail: HTMLImageElement): Promise<HTMLE
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoID = extractVideoID(thumbnail);
|
const videoID = await extractVideoIDFromElement(thumbnail);
|
||||||
if (!videoID) {
|
if (!videoID) {
|
||||||
hideThumbnailLabel(thumbnail);
|
hideThumbnailLabel(thumbnail);
|
||||||
return null;
|
return null;
|
||||||
@@ -61,7 +62,7 @@ function thumbnailHoverListener(e: MouseEvent) {
|
|||||||
let fetched = false;
|
let fetched = false;
|
||||||
const preFetch = async () => {
|
const preFetch = async () => {
|
||||||
fetched = true;
|
fetched = true;
|
||||||
const videoID = extractVideoID(thumbnail);
|
const videoID = await extractVideoIDFromElement(thumbnail);
|
||||||
if (videoID && await getHasStartSegment(videoID)) {
|
if (videoID && await getHasStartSegment(videoID)) {
|
||||||
void getSegmentsForVideo(videoID, false);
|
void getSegmentsForVideo(videoID, false);
|
||||||
}
|
}
|
||||||
@@ -84,18 +85,28 @@ function thumbnailHoverListener(e: MouseEvent) {
|
|||||||
function getLink(thumbnail: HTMLImageElement): HTMLAnchorElement | null {
|
function getLink(thumbnail: HTMLImageElement): HTMLAnchorElement | null {
|
||||||
if (isOnInvidious()) {
|
if (isOnInvidious()) {
|
||||||
return thumbnail.parentElement as HTMLAnchorElement | null;
|
return thumbnail.parentElement as HTMLAnchorElement | null;
|
||||||
} else if (thumbnail.nodeName.toLowerCase() === "yt-thumbnail-view-model") {
|
} else if (!onMobile()) {
|
||||||
return thumbnail.closest("yt-lockup-view-model")?.querySelector("a.yt-lockup-metadata-view-model-wiz__title");
|
const link = thumbnail.querySelector("a#thumbnail, a.reel-item-endpoint, a.yt-lockup-metadata-view-model__title, a.yt-lockup-metadata-view-model__title-link, a.yt-lockup-view-model__content-image, a.yt-lockup-metadata-view-model-wiz__title") as HTMLAnchorElement;
|
||||||
|
if (link) {
|
||||||
|
return link;
|
||||||
|
} else if (thumbnail.nodeName === "YTD-HERO-PLAYLIST-THUMBNAIL-RENDERER"
|
||||||
|
|| thumbnail.nodeName === "YT-THUMBNAIL-VIEW-MODEL"
|
||||||
|
) {
|
||||||
|
return thumbnail.closest("a") as HTMLAnchorElement;
|
||||||
} else {
|
} else {
|
||||||
return thumbnail.querySelector("#thumbnail");
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Big thumbnails, compact thumbnails, shorts, channel feature, playlist header
|
||||||
|
return thumbnail.querySelector("a.media-item-thumbnail-container, a.compact-media-item-image, a.reel-item-endpoint, :scope > a, .amsterdam-playlist-thumbnail-wrapper > a") as HTMLAnchorElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractVideoID(thumbnail: HTMLImageElement): VideoID | null {
|
async function extractVideoIDFromElement(thumbnail: HTMLImageElement): Promise<VideoID | null> {
|
||||||
const link = getLink(thumbnail);
|
const link = getLink(thumbnail);
|
||||||
if (!link || link.nodeName !== "A" || !link.href) return null; // no link found
|
if (!link || link.nodeName !== "A" || !link.href) return null; // no link found
|
||||||
|
|
||||||
return parseYouTubeVideoIDFromURL(link.href)?.videoID;
|
return await extractVideoID(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOldThumbnailLabel(thumbnail: HTMLImageElement): HTMLElement | null {
|
function getOldThumbnailLabel(thumbnail: HTMLImageElement): HTMLElement | null {
|
||||||
|
|||||||
Reference in New Issue
Block a user