Skip to content

fix(shortcuts): override arrow key volume step to respect shortcuts_volume_step - #4473

Open
parthrana-27 wants to merge 1 commit into
code-charity:masterfrom
parthrana-27:fix/arrow-key-volume-step
Open

parthrana-27 wants to merge 1 commit into
code-charity:masterfrom
parthrana-27:fix/arrow-key-volume-step

Conversation

@parthrana-27

Copy link
Copy Markdown
Contributor

What this fixes

Closes #4441

YouTube hardcodes a 5% volume step for its native ArrowUp/ArrowDown handlers, silently ignoring the value the user sets in ImprovedTube's Volume Step slider (shortcuts_volume_step).

Custom key bindings (e.g. A/Z mapped to volume) already work correctly 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.

Solution

In the keydown listener in shortcuts.js, after shortcutsHandler() runs (so configured shortcuts keep priority), check !event.defaultPrevented. If not already handled and the key is a bare ArrowUp/ArrowDown with no modifier keys, call shortcutIncreaseVolume() (which reads shortcuts_volume_step and syncs localStorage) and suppress the event.

Edge cases handled correctly:

  • A remapped ArrowUp (e.g. play/pause) triggers its configured shortcut via shortcutsHandler(), which calls event.preventDefault() — skipping the volume override entirely.
  • Modifier combos (Shift+ArrowUp, Ctrl+ArrowDown, etc.) are not intercepted.
  • If no player element is present, shortcutIncreaseVolume() logs and returns safely.

Changes

  • js&css/web-accessible/www.youtube.com/shortcuts.js — 15-line addition after shortcutsHandler() call
  • tests/unit/arrow-key-volume-step.test.js — 11 new unit tests

Testing

  • npx jest: 246/246 tests pass (was 235 before this PR)

…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
@parthrana-27 parthrana-27 mentioned this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Volume Step🐞

1 participant