From 86879183b2f599188c559117d02084776b64fadd Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Sun, 9 Jan 2022 23:17:20 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=B1=20Refactor=20bug=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/ytContent.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/scripts/ytContent.tsx b/src/scripts/ytContent.tsx index a0b80e0..a5799ec 100644 --- a/src/scripts/ytContent.tsx +++ b/src/scripts/ytContent.tsx @@ -128,7 +128,7 @@ window.addEventListener('load', async () => function getVideoTime(url: URL) { - return settings.redirect ? + return settings.redirect ? (url.searchParams.has('t') ? parseYouTubeURLTimeString(url.searchParams.get('t')!) : null) : (videoElement.currentTime > 3 && videoElement.currentTime < videoElement.duration - 1 ? videoElement.currentTime : null) } @@ -139,17 +139,15 @@ window.addEventListener('load', async () => if (url.pathname !== '/watch') return const videoId = url.searchParams.get('v') - if (!videoId) return - const lbryPathname = await requestLbryPathname(videoId) - if (!lbryPathname) return - const time = getVideoTime(url) - target = { lbryPathname, platfrom: targetPlatformSettings[settings.targetPlatform], time } + const lbryPathname = videoId && await requestLbryPathname(videoId) + if (lbryPathname) target = { lbryPathname, platfrom: targetPlatformSettings[settings.targetPlatform], time: getVideoTime(url) } + else target = null - if (settings.redirect) redirectTo(target) + if (settings.redirect) target && redirectTo(target) else updateButton(buttonMountPoint, target) } - videoElement.addEventListener('timeupdate', + videoElement.addEventListener('timeupdate', () => target && updateButton(buttonMountPoint, Object.assign(target, { time: getVideoTime(new URL(location.href)) }))) async function onUrlChange()