Auto Scroll with Adjustable Speed (c/v)

Auto scroll webpage with adjustable speed via 'c' and 'v' keys (0.1ms to 1000ms)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Scroll with Adjustable Speed (c/v)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Auto scroll webpage with adjustable speed via 'c' and 'v' keys (0.1ms to 1000ms)
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Default settings
    let scrollSpeed = 10;   // Default scroll speed in ms (higher = slower)
    const minSpeed = 0.1;    // Minimum scroll speed in ms (fastest)
    const maxSpeed = 1000;   // Maximum scroll speed in ms (slowest)
    const speedIncrement = 0.1; // Increment to adjust the scroll speed (ms)

    let scrollAmount = 10;  // Scroll amount per step (higher = faster scroll)
    let isScrolling = false;
    let scrollInterval;

    // Function to start auto-scrolling
    function startAutoScroll() {
        if (isScrolling) return; // Prevent multiple intervals
        isScrolling = true;
        scrollInterval = setInterval(() => {
            window.scrollBy(0, scrollAmount);
        }, scrollSpeed);
    }

    // Function to stop auto-scrolling
    function stopAutoScroll() {
        if (!isScrolling) return; // If it's not scrolling, do nothing
        isScrolling = false;
        clearInterval(scrollInterval);
    }

    // Function to increase scroll speed (faster scrolling)
    function increaseScrollSpeed() {
        if (scrollSpeed + speedIncrement <= maxSpeed) {
            scrollSpeed += speedIncrement;
            console.log(`Scroll speed increased to ${scrollSpeed}ms`);
        } else {
            console.log('Scroll speed is already at the maximum setting.');
        }
    }

    // Function to decrease scroll speed (slower scrolling)
    function decreaseScrollSpeed() {
        if (scrollSpeed - speedIncrement >= minSpeed) {
            scrollSpeed -= speedIncrement;
            console.log(`Scroll speed decreased to ${scrollSpeed}ms`);
        } else {
            console.log('Scroll speed is already at the minimum setting.');
        }
    }

    // Event listener for hotkeys (start with 'z', stop with 'x', adjust with 'c' and 'v')
    document.addEventListener('keydown', (event) => {
        if (event.key === 'z') { // 'z' to start scrolling
            startAutoScroll();
        } else if (event.key === 'x') { // 'x' to stop scrolling
            stopAutoScroll();
        } else if (event.key === 'c') { // 'c' to decrease scroll speed (slower)
            decreaseScrollSpeed();
        } else if (event.key === 'v') { // 'v' to increase scroll speed (faster)
            increaseScrollSpeed();
        }
    });

    console.log('Auto Scroll script loaded. Press "z" to start, "x" to stop, "c" to slow down, and "v" to speed up.');
})();