Created
February 28, 2025 19:22
-
-
Save Mariven/edfd5ffd841a1c213c0833e146aff74d to your computer and use it in GitHub Desktop.
Hold alt for fast scrolling
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
| // ==UserScript== | |
| // @name Fast Scroll with Alt | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Hold alt for fast scrolling | |
| // @author Mariven | |
| // @match *://*/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const scrollMultiplier = 4; | |
| let altKeyPressed = false; | |
| let didScroll = false; | |
| document.addEventListener('keydown', function(event) { | |
| if (event.key === 'Alt') | |
| altKeyPressed = true; | |
| }); | |
| document.addEventListener('keyup', function(event) { | |
| if (event.key === 'Alt') { | |
| altKeyPressed = false; | |
| if (didScroll) { | |
| // stop alt from toggling the menu bar iff alt was used to scroll | |
| event.preventDefault(); | |
| didScroll = false; | |
| } | |
| } | |
| }); | |
| window.addEventListener('blur', function() { | |
| // handle window blur to prevent stuck alt state | |
| altKeyPressed = false; | |
| }); | |
| document.addEventListener('wheel', function(event) { | |
| if (altKeyPressed) { | |
| event.preventDefault(); | |
| didScroll = true; | |
| const deltaX = event.deltaX * scrollMultiplier; | |
| const deltaY = event.deltaY * scrollMultiplier; | |
| if (event.deltaY !== 0) | |
| window.scrollBy({ | |
| top: deltaY, | |
| left: 0, | |
| }); | |
| if (event.deltaX !== 0) | |
| window.scrollBy({ | |
| top: 0, | |
| left: deltaX, | |
| }); | |
| } | |
| }, { passive: false }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment