tampermonkey自动滚动动态加载内容的页面
tampermonkey自动滚动动态加载内容的页面
// ==UserScript==
// @name 即时热榜
// @namespace http://tampermonkey.net/
// @version 2024-07-24
// @description try to take over the world!
// @author You
// @match https://m.jsrank.cn/
// @icon https://www.google.com/s2/favicons?sz=64&domain=jsrank.cn
// @grant none
// ==/UserScript==
(function() {
'use strict';
let autoScrolling = true;
let lastScrollY = 0;
const scrollThreshold = 30000; // 设置滚动的最大高度阈值
function scrollByStep() {
if (autoScrolling) {
const step = window.innerHeight / 2;
window.scrollBy(0, step);
const currentScrollY = window.pageYOffset;
if (currentScrollY < scrollThreshold) {
setTimeout(scrollByStep, 100); // 继续滚动
} else {
console.log('滚动完成或达到高度阈值');
autoScrolling = false;
}
}
}
window.addEventListener('scroll', function() {
console.log('scroll',window.pageYOffset,window.scrollY);
lastScrollY = window.scrollY;
const currentScrollY = window.pageYOffset;
// if(currentScrollY >scrollThreshold){
// autoScrolling = false; // 用户手动滚动后停止自动滚动
// };
});
window.addEventListener('wheel', function(event) {
console.log('wheel',event.deltaY);
if (Math.abs(event.deltaY) > 0) {
autoScrolling = false; // 用户向下滚动时停止自动滚动
}
});
setTimeout(scrollByStep, 1000); // 延迟3秒后开始滚动
// Your code here...
})();