Created
February 18, 2025 09:14
-
-
Save azer/e8b05846f96ca2ba5d06faa9f96ae36a to your computer and use it in GitHub Desktop.
Bookmarklet to auto scroll a web page
This file contains 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
javascript:(function() { | |
// Prompt for scroll speed (pixels per second), default 75 | |
const speed = prompt('Enter scroll speed (pixels per second):', '75'); | |
if (!speed) return; // Exit if canceled | |
// Convert speed to pixels per frame (assuming 60fps) | |
const pixelsPerFrame = parseFloat(speed) / 60; | |
// Store initial scroll position | |
let currentPosition = window.scrollY; | |
// Get maximum scroll height | |
const maxScroll = Math.max( | |
document.body.scrollHeight, | |
document.documentElement.scrollHeight, | |
document.body.offsetHeight, | |
document.documentElement.offsetHeight, | |
document.body.clientHeight, | |
document.documentElement.clientHeight | |
) - window.innerHeight; | |
// Scroll function | |
function scroll() { | |
currentPosition += pixelsPerFrame; | |
// Stop at the bottom | |
if (currentPosition >= maxScroll) { | |
return; | |
} | |
window.scrollTo(0, currentPosition); | |
requestAnimationFrame(scroll); | |
} | |
// Start scrolling | |
scroll(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment