From 798a7354e386e675210f6d096ab2ff6953c5b2ee Mon Sep 17 00:00:00 2001 From: Hakadao Date: Tue, 19 Sep 2023 17:05:43 +0800 Subject: [PATCH] fix: fix current Url variable undefined issue --- src/contentScripts/index.ts | 39 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/contentScripts/index.ts b/src/contentScripts/index.ts index a510ae7b..fabc06b6 100644 --- a/src/contentScripts/index.ts +++ b/src/contentScripts/index.ts @@ -28,25 +28,28 @@ if (isFirefox) { injectApp() isFirstScriptExecute = false - }) - // Handling for video page to prevent the issue of video being played but the page remaining empty - if ( - // video page - /https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl) - // watch later playlist - || /https?:\/\/(www.)?bilibili.com\/list\/watchlater.*/.test(currentUrl) - // favorite playlist - || /https?:\/\/(www.)?bilibili.com\/list\/ml.*/.test(currentUrl) - ) { - setTimeout(() => { - document.documentElement.removeChild(beforeLoadedStyleEl) - }, 800) - } - else { - window.onload = () => { - document.documentElement.removeChild(beforeLoadedStyleEl) + + const currentUrl = document.URL + + // Handling for video page to prevent the issue of video being played but the page remaining empty + if ( + // video page + /https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl) + // watch later playlist + || /https?:\/\/(www.)?bilibili.com\/list\/watchlater.*/.test(currentUrl) + // favorite playlist + || /https?:\/\/(www.)?bilibili.com\/list\/ml.*/.test(currentUrl) + ) { + setTimeout(() => { + document.documentElement.removeChild(beforeLoadedStyleEl) + }, 800) } - } + else { + window.onload = () => { + document.documentElement.removeChild(beforeLoadedStyleEl) + } + } + }) } else { document.addEventListener('DOMContentLoaded', () => {