MCPcopy Index your code
hub / github.com/XIU2/UserScript / windowScroll

Function windowScroll

Autopage.user.js:2938–2958  ·  view source on GitHub ↗
(fn1)

Source from the content-addressed store, hash-verified

2936 }
2937 // 滚动条事件
2938 function windowScroll(fn1) {
2939 var beforeScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
2940 fn = fn1 || function () {};
2941 setTimeout(function () { // 延时 1 秒执行,避免刚载入到页面就触发翻页事件
2942
2943 // 避免网页内容太少,高度撑不起来,不显示滚动条而无法触发翻页事件
2944 let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
2945 scrollHeight = window.innerHeight || document.documentElement.clientHeight
2946 if (scrollTop === 0 && document.documentElement.scrollHeight === scrollHeight) {
2947 insStyle(`html, body {min-height: ${document.documentElement.scrollHeight+10}px;}`)
2948 }
2949
2950 window.addEventListener('scroll', function (e) {
2951 var afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
2952 delta = afterScrollTop - beforeScrollTop;
2953 if (delta == 0) return false;
2954 fn(delta > 0 ? 'down' : 'up', e);
2955 beforeScrollTop = afterScrollTop;
2956 }, false);
2957 }, 1000)
2958 }
2959 // 自定义 urlchange 事件(用来监听 URL 变化)
2960 function addUrlChangeEvent() {
2961 history.pushState = ( f => function pushState(){

Callers 1

pageLoadingFunction · 0.70

Calls 1

insStyleFunction · 0.85

Tested by

no test coverage detected