🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/14 21:52:30
🔄 下次更新时间:2026/01/14 22:52:30
手动刷新缓存

AutoScroll2

AutoScroll - Automatically scroll down the page, supporting hotkey control switches and speed adjustment (自动向下滚动页面,支持热键控制开关和速度调节)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name        AutoScroll2
// @description AutoScroll - Automatically scroll down the page, supporting hotkey control switches and speed adjustment (自动向下滚动页面,支持热键控制开关和速度调节)
// @include     http*
// @version     1.0.2
// @author      Eilen https://github.com/EilenC
// @grant       none
// @namespace https://greasyfork.org/users/319354
// @supportURL https://github.com/EilenC/Tampermonkey-Scripts/blob/master/AutoScroll2/AutoScroll2.js
// ==/UserScript==

(function (document) {
    'use strict';

    function roundToTwoDecimalPlaces(number) {
        return Number(number.toFixed(2));
    }

    let notificationTimer = null;
    let notification = document.createElement('div');
    let tipsTime = 300;

    function showNotification(message, duration) {
        clearTimeout(notificationTimer);
        notification.textContent = message;
        notification.style.position = 'fixed';
        notification.style.top = '50%';
        notification.style.left = '50%';
        notification.style.transform = 'translate(-50%, -50%)';
        notification.style.background = 'black';
        notification.style.color = 'white';
        notification.style.fontWeight = 'bold';
        notification.style.fontSize = '40px';
        notification.style.padding = '20px';
        notification.style.borderRadius = '10px';
        notification.style.zIndex = '9999';
        document.body.appendChild(notification);
        notificationTimer = setTimeout(function () {
            document.body.removeChild(notification);
            notificationTimer = null;
        }, duration);
    }

    let scrollY = 0;
    let scrollSpeed = 0.5; // 默认滚动速度
    let isScrolling = false;

    let lastScrollTime = performance.now();
    const targetFrameDelay = 1000 / 60; // 目标帧率为每秒 60 帧
    let animationFrameId = null;

    function scrollAnimation(currentTime) {
        if (isScrolling) {
            const elapsedTime = currentTime - lastScrollTime;
            if (elapsedTime >= targetFrameDelay) {
                const deltaScroll = scrollSpeed * (elapsedTime / targetFrameDelay);
                scrollY += deltaScroll;
                window.scrollTo(0, scrollY);
                lastScrollTime = currentTime;
            }
            animationFrameId = requestAnimationFrame(scrollAnimation);
        } else {
            cancelAnimationFrame(animationFrameId);
            animationFrameId = null;
        }
    }

    // 开始滚动
    function startScroll() {
        isScrolling = true;
        scrollY = window.scrollY || document.documentElement.scrollTop;
        lastScrollTime = performance.now();
        animationFrameId = requestAnimationFrame(scrollAnimation);
    }

    // 停止滚动
    function stopScroll() {
        isScrolling = false;
        if (animationFrameId !== null) {
            cancelAnimationFrame(animationFrameId);
            animationFrameId = null;
        }
        scrollY = 0; // 清空滚动位置
        lastScrollTime = 0; // 重置上次滚动时间
    }

    let lastKeyDownTime = 0;
    let keyDownCount = 0;
    // 键盘事件处理
    document.addEventListener('keydown', (event) => {
        let currentTime = new Date().getTime();
        switch (event.key) {
            case 's':
            case 'ArrowLeft':
                if(isScrolling){
                    let step = 0.01
                    if (scrollSpeed > 2) {
                        step = 0.1
                    }
                    scrollSpeed = Math.max(scrollSpeed - step, 0.01);
                    showNotification('AutoScroll:Speed: ' + roundToTwoDecimalPlaces(scrollSpeed), tipsTime);
                }
                break;
            case 'a':
            case 'ArrowRight':
                if(isScrolling){
                    scrollSpeed = Math.min(scrollSpeed + 0.1, 99);
                    showNotification('AutoScroll:Speed: ' + roundToTwoDecimalPlaces(scrollSpeed), tipsTime);
                }
                break;
            case "`":
                if (currentTime - lastKeyDownTime < 300) {
                    keyDownCount++;
                } else {
                    keyDownCount = 1;
                }

                lastKeyDownTime = currentTime;

                if (keyDownCount === 2) {
                    if (isScrolling) {
                        stopScroll();
                        showNotification('AutoScroll:Off', tipsTime);
                    } else {
                        startScroll();
                        showNotification('AutoScroll:On', tipsTime);
                    }
                    keyDownCount = 0;
                }
                break;
        }
    });
})(document);