mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 22:17:21 +03:00
Fix next chapter hotkey causing multiple chapters to be skipped
Fixes #2273
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user