Repository navigation
fix(shortcuts): override arrow key volume step to respect shortcuts_volume_step - #4473
Open
parthrana-27 wants to merge 1 commit into
Open
parthrana-27 wants to merge 1 commit into
parthrana-27 wants to merge 1 commit into
Conversation
…olume_step YouTube hardcodes a 5% volume step for its native ArrowUp/ArrowDown handlers, silently ignoring the value set in ImprovedTube's 'Volume Step' slider (shortcuts_volume_step). Custom key bindings (e.g. A/Z mapped to volume) already work because ImprovedTube intercepts those via shortcutsHandler(). The gap was that bare ArrowUp/ArrowDown without a user-configured binding fell through to YouTube's native handler untouched. Fix: after shortcutsHandler() runs and all configured shortcuts have had first priority, check whether the event was already handled (!event.defaultPrevented). If not, and the key is a bare ArrowUp (38) or ArrowDown (40) with no modifier keys held, call shortcutIncreaseVolume() with the user-configured step and suppress the event so YouTube's native handler never fires. This preserves all edge cases: - A remapped ArrowUp (e.g. play/pause) triggers its configured shortcut via shortcutsHandler() which sets defaultPrevented, skipping the volume override. - Modifier combos (Shift+ArrowUp etc.) are not intercepted. Closes code-charity#4441
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
Closes #4441
YouTube hardcodes a 5% volume step for its native
ArrowUp/ArrowDownhandlers, silently ignoring the value the user sets in ImprovedTube's Volume Step slider (shortcuts_volume_step).Custom key bindings (e.g.
A/Zmapped to volume) already work correctly because ImprovedTube intercepts those viashortcutsHandler(). The gap was that bareArrowUp/ArrowDownwithout a user-configured binding fell through to YouTube's native handler untouched.Solution
In the
keydownlistener inshortcuts.js, aftershortcutsHandler()runs (so configured shortcuts keep priority), check!event.defaultPrevented. If not already handled and the key is a bareArrowUp/ArrowDownwith no modifier keys, callshortcutIncreaseVolume()(which readsshortcuts_volume_stepand syncslocalStorage) and suppress the event.Edge cases handled correctly:
ArrowUp(e.g. play/pause) triggers its configured shortcut viashortcutsHandler(), which callsevent.preventDefault()— skipping the volume override entirely.Shift+ArrowUp,Ctrl+ArrowDown, etc.) are not intercepted.shortcutIncreaseVolume()logs and returns safely.Changes
js&css/web-accessible/www.youtube.com/shortcuts.js— 15-line addition aftershortcutsHandler()calltests/unit/arrow-key-volume-step.test.js— 11 new unit testsTesting
npx jest: 246/246 tests pass (was 235 before this PR)