HotKeyTopBottomScroll

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);

})();