Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Jan 15, 2025
1 parent 6f41f88 commit c0ceabd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ function resetValues() {
}

async function videoIDChange(): Promise<void> {
console.log("Video ID changed");
//setup the preview bar
if (previewBar === null) {
waitFor(getControls).then(createPreviewBar);
Expand All @@ -507,6 +508,7 @@ async function videoIDChange(): Promise<void> {
});

sponsorsLookup();
checkPageForNewThumbnails();

// Clear unsubmitted segments from the previous video
sponsorTimesSubmitting = [];
Expand Down
1 change: 1 addition & 0 deletions src/requests/videoLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function getLabelHashBlock(hashPrefix: string, refreshCache: boolean = fal
}

export async function getVideoLabel(videoID: VideoID, refreshCache: boolean = false): Promise<Category | null> {
return "sponsor" as Category;
const prefix = (await getVideoIDHash(videoID)).slice(0, 3);
const result = await getLabelHashBlock(prefix, refreshCache);

Expand Down
3 changes: 3 additions & 0 deletions src/thumbnail-utils/thumbnailManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 15 additions & 2 deletions src/thumbnail-utils/thumbnails.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -90,10 +91,22 @@ async function hideThumbnailLabel(thumbnail: HTMLElement): Promise<void> {
}
}

const preloadSegments = (e: MouseEvent) => {

Check failure on line 94 in src/thumbnail-utils/thumbnails.ts

View workflow job for this annotation

GitHub Actions / Create artifacts

'e' is defined but never used
// 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 {
Expand Down

0 comments on commit c0ceabd

Please sign in to comment.