Auto Scroll

Auto Scroll Pages (double click / ctrl+arrow)

目前為 2019-12-06 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto Scroll
// @description  Auto Scroll Pages (double click / ctrl+arrow)
// @include      *
// @version      0.12
// @author       Erimus
// @grant        none
// @namespace    https://greasyfork.org/users/46393
// ==/UserScript==

(function(document) {

    // speed controlled by the following 2 variables
    let scroll_interval = 15, // every xx ms
        scroll_distance = 1 // move xx pixel

    let scrolling = false, // status
        auto_scroll // scroll function

    // main function
    let toggle_scroll = function(dire) {
        scrolling = !scrolling
        if (scrolling) {
            console.log('Start scroll', dire)
            dire = dire == 'up' ? -1 : 1
            auto_scroll = setInterval(function() {
                document.documentElement.scrollTop += (dire * scroll_distance)
            }, scroll_interval)
        } else {
            console.log('Stop scroll')
            clearInterval(auto_scroll)
        }
    }

    // toogle scrolling by double click
    document.body.addEventListener('dblclick', toggle_scroll)

    // single click to stop scroll
    document.body.addEventListener('click', function() {
        scrolling = false
        console.log('Stop scroll')
        clearInterval(auto_scroll)
    })

    // toogle scrolling by hotkey
    // https://www.w3.org/2002/09/tests/keys.html
    document.onkeydown = function(e) {
        let keyCode = e.keyCode || e.which || e.charCode
        let ctrlKey = e.ctrlKey || e.metaKey
        if (ctrlKey && keyCode == 40) {
            console.log('Press Ctrl + Down arrow')
            toggle_scroll()
        } else if (ctrlKey && keyCode == 38) {
            console.log('Press Ctrl + Up arrow')
            toggle_scroll('up')
        }
    }

})(document)