diff --git a/src/content.ts b/src/content.ts index 76b765d5..bdb9a754 100644 --- a/src/content.ts +++ b/src/content.ts @@ -70,6 +70,8 @@ import { openWarningDialog } from "./utils/warnings"; cleanPage(); +detectPageType(); + const utils = new Utils(); waitFor(() => Config.isReady(), 5000, 10).then(() => { @@ -81,8 +83,6 @@ waitFor(() => Config.isReady(), 5000, 10).then(() => { ) DynamicListener(); }); -detectPageType(); - if ((document.hidden && getPageType() == PageType.Video) || getPageType() == PageType.List) { document.addEventListener("visibilitychange", () => videoElementChange(true, getVideo()), { once: true }); window.addEventListener("mouseover", () => videoElementChange(true, getVideo()), { once: true }); diff --git a/src/thumbnail-utils/thumbnailManagement.ts b/src/thumbnail-utils/thumbnailManagement.ts index cef0656f..d9db6ab7 100644 --- a/src/thumbnail-utils/thumbnailManagement.ts +++ b/src/thumbnail-utils/thumbnailManagement.ts @@ -1,5 +1,6 @@ import Config from "../config"; import { getPageLoaded } from "../content"; +import { PageType } from "../types"; import { waitFor } from "../utils/"; import { addCleanupListener } from "../utils/cleanup"; import { getPageType } from "../utils/video"; @@ -55,6 +56,9 @@ function onInitialLoad() { let thumbnailCheckTimeout: NodeJS.Timer | null = null; export function checkPageForNewThumbnails() { + // disable on live pages to prevent memory leaks + if (getPageType() === PageType.Live) return; + if (performance.now() - lastThumbnailCheck < 100 || thumbnailCheckTimeout) { if (!thumbnailCheckTimeout) { thumbnailCheckTimeout = setTimeout(() => { diff --git a/src/utils/video.ts b/src/utils/video.ts index 8289162f..72578f83 100644 --- a/src/utils/video.ts +++ b/src/utils/video.ts @@ -212,7 +212,7 @@ export async function whitelistCheck() { contentMethod.channelIDChange(channelIDInfo); } -export function detectPageType(): void { +export function detectPageType(): PageType { pageType = PageType.Unknown; const urlObject = new URL(document.URL); @@ -243,6 +243,7 @@ export function detectPageType(): void { } else if (urlObject.hostname === "live.bilibili.com") { pageType = PageType.Live; } + return pageType; } let lastMutationListenerCheck = 0;