Greasy Fork

Greasy Fork is available in English.

autoScroll

It allows the page to scroll on its own

当前为 2021-05-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         autoScroll
// @namespace    eyes
// @version      0.1
// @description  It allows the page to scroll on its own
// @author       eyes
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
            var speed = 0;
        // 获取滑动位置
        function 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;
        }
        //文档的总高度
        function 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;
        }
        //浏览器视口的高度
        function getWindowHeight() {
            var windowHeight = 0;
            if (document.compatMode == 'CSS1Compat') {
                windowHeight = document.documentElement.clientHeight;
            } else {
                windowHeight = document.body.clientHeight;
            }
            return windowHeight;
        }

        // 滚动事件
        setInterval(() => {
            // 判断页面是否滑到底部
            let bottomFlag = (getScrollTop() + getWindowHeight() == getScrollHeight()) ? true : false;
            if (bottomFlag) {
                speed = 0;
            } else {
                document.documentElement.scrollTop += speed;
            }
        }, 5)

        // 判断是否需要滚动
        document.onkeydown = (e) => {
            e = event || window.event;
            if (e && e.keyCode == 38 && e.altKey) { // 上键
                let bottomFlag = (getScrollTop() + getWindowHeight() == getScrollHeight()) ? true : false;
                if (bottomFlag) {
                    document.documentElement.scrollTop += -1;
                }
                speed -= 1.5;
            }
            if (e && e.keyCode == 40 && e.altKey) { // 下键
                speed += 1.5;
            }
        }

        // 单击页面停止滚动
        document.onclick = () => {
            speed = 0;
        }

        // 滑动滚轮页面停止滚动
        document.onmousewheel = () => {
            speed = 0;
        }
        document.addEventListener("DOMMouseScroll", () => {
            speed = 0;
        })
})();