1
0

Ooops forgot to commit

This commit is contained in:
2025-11-25 12:20:00 -05:00
parent 4964211254
commit 5209e8cf26
7 changed files with 407 additions and 67 deletions

View File

@@ -67,8 +67,122 @@ async function hideLogo(page) {
}
}
/**
* Start smooth auto-scrolling on the page
* @param {Page} page - Puppeteer page
* @param {Object} options - Scrolling options
* @param {number} options.pauseAtTop - Seconds to wait at top before scrolling (default: 30)
* @param {number} options.fps - Frame rate for smooth scrolling (default: 30)
* @returns {Function} Stop function to cancel scrolling
*/
async function startAutoScroll(page, { pauseAtTop = 30, fps = 30 } = {}) {
let stopScrolling = false;
const stopFunction = () => {
stopScrolling = true;
};
// Inject scrolling logic into the page
await page.evaluate((pauseMs, captureFrameRate) => {
window.__autoScrollState = {
stopScrolling: false,
isScrolling: false
};
function smoothScroll() {
if (window.__autoScrollState.stopScrolling) return;
const maxScroll = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
) - window.innerHeight;
if (maxScroll <= 0) {
// Page is not scrollable, just wait
setTimeout(() => {
if (!window.__autoScrollState.stopScrolling) {
smoothScroll();
}
}, pauseMs);
return;
}
// Wait at top, then start smooth scroll
setTimeout(() => {
if (window.__autoScrollState.stopScrolling) return;
// Slow scroll speed for smooth appearance
// At 60fps with 30px/s = 0.5 pixels per frame
const pixelsPerSecond = 30;
const pixelsPerFrame = pixelsPerSecond / captureFrameRate;
const frameInterval = 1000 / captureFrameRate;
function scrollDown() {
if (window.__autoScrollState.stopScrolling) return;
let currentPos = window.scrollY;
const interval = setInterval(() => {
if (window.__autoScrollState.stopScrolling) {
clearInterval(interval);
return;
}
currentPos += pixelsPerFrame;
if (currentPos >= maxScroll) {
window.scrollTo(0, maxScroll);
clearInterval(interval);
setTimeout(() => {
if (!window.__autoScrollState.stopScrolling) {
scrollUp();
}
}, 2000);
} else {
window.scrollTo(0, currentPos);
}
}, frameInterval);
}
function scrollUp() {
if (window.__autoScrollState.stopScrolling) return;
let currentPos = window.scrollY;
const interval = setInterval(() => {
if (window.__autoScrollState.stopScrolling) {
clearInterval(interval);
return;
}
currentPos -= pixelsPerFrame;
if (currentPos <= 0) {
window.scrollTo(0, 0);
clearInterval(interval);
if (!window.__autoScrollState.stopScrolling) {
smoothScroll();
}
} else {
window.scrollTo(0, currentPos);
}
}, frameInterval);
}
scrollDown();
}, pauseMs);
}
// Start scrolling
smoothScroll();
}, pauseAtTop * 1000, fps);
return stopFunction;
}
module.exports = {
setupPage,
waitForPageFullyLoaded,
hideLogo
hideLogo,
startAutoScroll
};