Skip to content

Instantly share code, notes, and snippets.

@suchasplus
Created March 20, 2026 18:24
Show Gist options
  • Select an option

  • Save suchasplus/19c7bdd0cc3325d8f7b223bf0f5c937e to your computer and use it in GitHub Desktop.

Select an option

Save suchasplus/19c7bdd0cc3325d8f7b223bf0f5c937e to your computer and use it in GitHub Desktop.
discourse 刷阅读量 from opus4.6
(async () => {
const SCROLL_STEP = 300; // 每次滚动像素
const SCROLL_INTERVAL = 800; // 滚动间隔(ms)
const IDLE_WAIT = 3000; // 到底后等待加载时间(ms)
const MAX_IDLE_RETRIES = 5; // 最大等待加载重试次数
const sleep = ms => new Promise(r => setTimeout(r, ms));
let idleCount = 0;
let lastHeight = 0;
console.log('🐙 开始自动滚动...');
while (true) {
window.scrollBy({ top: SCROLL_STEP, behavior: 'smooth' });
await sleep(SCROLL_INTERVAL);
const currentHeight = document.documentElement.scrollHeight;
const scrollPos = window.scrollY + window.innerHeight;
// 判断是否到达底部(留 5px 容差)
if (scrollPos >= currentHeight - 5) {
if (currentHeight === lastHeight) {
idleCount++;
console.log(`⏳ 等待加载... (${idleCount}/${MAX_IDLE_RETRIES})`);
if (idleCount >= MAX_IDLE_RETRIES) {
console.log('✅ 已到达页面底部,滚动结束。');
break;
}
await sleep(IDLE_WAIT);
} else {
// 页面高度变了,说明加载了新内容
idleCount = 0;
}
lastHeight = currentHeight;
} else {
idleCount = 0;
lastHeight = currentHeight;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment