From cf4d13a7568832f00d4ca8b4d70ce8e54464987a Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 24 May 2025 02:07:36 -0400 Subject: [PATCH] Fix next chapter hotkey causing multiple chapters to be skipped Fixes #2273 --- src/content.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/content.ts b/src/content.ts index 43a2f08e..673e7ae1 100644 --- a/src/content.ts +++ b/src/content.ts @@ -2623,9 +2623,11 @@ function addHotkeyListener(): void { // Allow us to stop propagation to YouTube by being deeper document.removeEventListener("keydown", hotkeyListener); document.body.addEventListener("keydown", hotkeyListener); + document.body.addEventListener("keyup", hotkeyPropagationListener); addCleanupListener(() => { document.body.removeEventListener("keydown", hotkeyListener); + document.body.removeEventListener("keyup", hotkeyPropagationListener); }); }; @@ -2713,6 +2715,32 @@ function hotkeyListener(e: KeyboardEvent): void { } } +function hotkeyPropagationListener(e: KeyboardEvent): void { + if ((["textarea", "input"].includes(document.activeElement?.tagName?.toLowerCase()) + || (document.activeElement as HTMLElement)?.isContentEditable + || document.activeElement?.id?.toLowerCase()?.match(/editable|input/)) + && document.hasFocus()) return; + + const key: Keybind = { + key: e.key, + code: e.code, + alt: e.altKey, + ctrl: e.ctrlKey, + shift: e.shiftKey + }; + + const nextChapterKey = Config.config.nextChapterKeybind; + const previousChapterKey = Config.config.previousChapterKeybind; + + if (keybindEquals(key, nextChapterKey)) { + if (sponsorTimes.length > 0) e.stopPropagation(); + return; + } else if (keybindEquals(key, previousChapterKey)) { + if (sponsorTimes.length > 0) e.stopPropagation(); + return; + } +} + /** * Adds the CSS to the page if needed. Required on optional sites with Chrome. */