HotKeyTopBottomScroll

use alt+up/down to scroll to top/bottom

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         HotKeyTopBottomScroll
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  use alt+up/down to scroll to top/bottom
// @author       Kiddo
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('keydown', function(event) {
        // 1. 检查是否满足“只有 Alt”的条件:
        if (!event.altKey || event.ctrlKey || event.shiftKey || event.metaKey) {
            return;
        }

        let scrolled = false; // 标记是否执行了滚动操作

        // 2. 检查具体的按键
        switch (event.key) {
            case 'ArrowUp':
                // 触发:(仅) Alt + 上方向键
                window.scrollTo({
                    top: 0,
                    behavior: 'auto'
                });
                scrolled = true;
                break;

            case 'ArrowDown':
                // 触发:(仅) Alt + 下方向键
                window.scrollTo({
                    top: Number.MAX_SAFE_INTEGER,
                    behavior: 'auto'
                });
                scrolled = true;
                break;
            default:
                // 如果按下的不是方向键 (例如只按了 Alt),则什么也不做
                return;
        }

        // 3. 阻止默认行为
        if (scrolled) {
            event.preventDefault();
        }

    }, true);

})();