diff --git a/src/content.ts b/src/content.ts index 63cf3969..6d961d0d 100644 --- a/src/content.ts +++ b/src/content.ts @@ -494,6 +494,7 @@ function resetValues() { } async function videoIDChange(): Promise { + console.log("Video ID changed"); //setup the preview bar if (previewBar === null) { waitFor(getControls).then(createPreviewBar); @@ -507,6 +508,7 @@ async function videoIDChange(): Promise { }); sponsorsLookup(); + checkPageForNewThumbnails(); // Clear unsubmitted segments from the previous video sponsorTimesSubmitting = []; diff --git a/src/requests/videoLabels.ts b/src/requests/videoLabels.ts index 5e25385f..b6149880 100644 --- a/src/requests/videoLabels.ts +++ b/src/requests/videoLabels.ts @@ -59,6 +59,7 @@ async function getLabelHashBlock(hashPrefix: string, refreshCache: boolean = fal } export async function getVideoLabel(videoID: VideoID, refreshCache: boolean = false): Promise { + return "sponsor" as Category; const prefix = (await getVideoIDHash(videoID)).slice(0, 3); const result = await getLabelHashBlock(prefix, refreshCache); diff --git a/src/thumbnail-utils/thumbnailManagement.ts b/src/thumbnail-utils/thumbnailManagement.ts index bb4e86c7..672555f0 100644 --- a/src/thumbnail-utils/thumbnailManagement.ts +++ b/src/thumbnail-utils/thumbnailManagement.ts @@ -76,6 +76,9 @@ export function checkPageForNewThumbnails() { } async function labelNewThumbnails(container: Element, containerType: string) { + if (containerType === "playerSideRecommendation") { + console.log("playerSideRecommendation", container); + } if (shouldWaitForPageLoad(containerType)) { await waitFor(getPageLoaded, 30000, 10); } diff --git a/src/thumbnail-utils/thumbnails.ts b/src/thumbnail-utils/thumbnails.ts index b30c6c87..94a6d6fe 100644 --- a/src/thumbnail-utils/thumbnails.ts +++ b/src/thumbnail-utils/thumbnails.ts @@ -1,5 +1,6 @@ import Config from "../config"; import { getVideoLabel } from "../requests/videoLabels"; +import { VideoID } from "../types"; import { waitFor } from "../utils/"; import { getBvIDFromURL } from "../utils/parseVideoID"; import { getLabelAnchorSelector, getLinkAttribute, getLinkSelectors } from "./thumbnail-selectors"; @@ -52,7 +53,7 @@ export async function labelThumbnailProcess( const [videoID] = videoIDs; // 获取或创建缩略图标签 - const { overlay, text } = await createOrGetThumbnail(thumbnail, containerType); + const { overlay, text } = await createOrGetThumbnail(thumbnail, containerType, videoID); const category = await getVideoLabel(videoID); if (!category) { @@ -90,10 +91,22 @@ async function hideThumbnailLabel(thumbnail: HTMLElement): Promise { } } +const preloadSegments = (e: MouseEvent) => { + // console.log("pointerenter", (e.target as HTMLElement).getAttribute("data-bsb-bvid")); +}; + async function createOrGetThumbnail( thumbnail: HTMLElement, - containerType: string + containerType: string, + videoID: VideoID ): Promise<{ overlay: HTMLElement; text: HTMLElement }> { + // only add evnet listener once, add preloadSegments to thumbnail when pointerenter + if (thumbnail.getAttribute("data-bsb-bvid") != videoID) { + thumbnail.setAttribute("data-bsb-bvid", videoID); + thumbnail.removeEventListener("mouseenter", preloadSegments); + thumbnail.addEventListener("mouseenter", preloadSegments); + } + const oldLabelElement = await getOldThumbnailLabel(thumbnail); if (oldLabelElement) { return {