就改滑动条。只在一个网页上修改就行(到时候给你说哪个网站),修改网页里面的滑动条,而不是网页滑动条!!!
// ==UserScript==
// @name autoScroll
// @namespace eyes
// @version 1.3.0
// @description It allows the page to scroll on its own
// @author eyes
// @match :///*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let speed = 0;
// 获取滑动位置
let getScrollTop = () => {
var scrollTop = 0,
bodyScrollTop = 0,
documentScrollTop = 0;
if (document.body) {
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
return scrollTop;
}
//浏览器视口的高度
let getWindowHeight = () => {
var windowHeight = 0;
if (document.compatMode == 'CSS1Compat') {
windowHeight = document.documentElement.clientHeight;
} else {
windowHeight = document.body.clientHeight;
}
return windowHeight;
}
//文档的总高度
let getScrollHeight = () => {
var scrollHeight = 0,
bodyScrollHeight = 0,
documentScrollHeight = 0;
if (document.body) {
bodyScrollHeight = document.body.scrollHeight;
}
if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight;
}
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
return scrollHeight;
}
// 滚动事件
setInterval(() => {
// 判断页面是否滑到底部
let bottomFlag = (getScrollTop() + getWindowHeight() == getScrollHeight()) ? true : false;
let topFlag = (getScrollTop() == 0) ? true : false;
if (bottomFlag || topFlag) {
speed = 0;
} else {
document.documentElement.scrollTop += speed;
}
}, 5)
// 判断是否需要滚动
document.onkeydown = (e) => {
e = event || window.event;
// 同时按上键与alt键向上滚动
if (e && e.keyCode == 38 && e.altKey) {
let bottomFlag = (getScrollTop() + getWindowHeight() == getScrollHeight()) ? true : false;
if (bottomFlag) {
document.documentElement.scrollTop += -1;
}
speed -= 1.5;
}
// 同时按下键与alt键向下滚动
if (e && e.keyCode == 40 && e.altKey) {
let topFlag = (getScrollTop() == 0) ? true : false;
if (topFlag) {
document.documentElement.scrollTop += 1;
}
speed += 1.5;
}
// 同时按 CTRL + ALT 键停止滚动
if (e && e.altKey && e.ctrlKey) {
speed = 0;
}
}
// 单击页面停止滚动
document.onclick = () => {
speed = 0;
}
// 滑动滚轮页面停止滚动
document.onmousewheel = () => {
speed = 0;
}
document.addEventListener("DOMMouseScroll", () => {
speed = 0;
})
})();
看到代码里面的 document.documentElement 了吗?这就是滚动的主体,只需要在网页里用 js 找到中间那个滚动控件的 document 应该就好了。
联系我,我给你看看改改