Created
December 6, 2024 10:16
-
-
Save hackingbutlegal/1fb253f80c829daf5f5aaf6e8c5dc502 to your computer and use it in GitHub Desktop.
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
| // Function to scroll to bottom with configurable parameters | |
| function scrollToBottom({ | |
| scrollInterval = 100, // How often to scroll in milliseconds | |
| scrollStep = 150, // How many pixels to scroll each time | |
| maxScrolls = 1000 // Safety limit to prevent infinite loops | |
| } = {}) { | |
| return new Promise((resolve, reject) => { | |
| let scrollCount = 0; | |
| const previousHeight = document.documentElement.scrollHeight; | |
| const scroll = setInterval(() => { | |
| // Scroll down by step size | |
| window.scrollBy(0, scrollStep); | |
| scrollCount++; | |
| // Get current scroll position and page height | |
| const scrollPosition = window.scrollY + window.innerHeight; | |
| const currentHeight = document.documentElement.scrollHeight; | |
| // Check if we've reached the bottom (no height change after scroll) | |
| if (scrollPosition >= currentHeight && currentHeight === previousHeight) { | |
| clearInterval(scroll); | |
| resolve('Reached the bottom of the page'); | |
| } | |
| // Stop if we hit the maximum number of scrolls | |
| if (scrollCount >= maxScrolls) { | |
| clearInterval(scroll); | |
| resolve('Reached maximum scroll limit'); | |
| } | |
| }, scrollInterval); | |
| }); | |
| } | |
| // Usage example | |
| scrollToBottom({ | |
| scrollInterval: 100, // Scroll every 150ms | |
| scrollStep: 150, // Scroll 150px each time | |
| maxScrolls: 5000 // Maximum 5000 scroll attempts | |
| }).then(result => console.log(result)); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Avoid rate limit:
scrollInterval: 1500, // Scroll every 1500ms
scrollStep: 500, // Scroll 500px each time