Double W and Double S Key Page Scroll

将 'ww' 映射为 Page Up 和 'ss' 映射为 Page Down

// ==UserScript==
// @name         Double W and Double S Key Page Scroll
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  将 'ww' 映射为 Page Up 和 'ss' 映射为 Page Down
// @author       yueli
// @match        *://*/*
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let wCount = 0;
    let sCount = 0;
    const resetTime = 500; // 毫秒

    document.addEventListener('keydown', function(event) {
        if (event.key === 'w') {
            wCount++;
            sCount = 0;
            setTimeout(() => wCount = 0, resetTime);
            if (wCount === 2) {
                window.scrollBy(0, -window.innerHeight);
                wCount = 0;
            }
        } else if (event.key === 's') {
            sCount++;
            wCount = 0;
            setTimeout(() => sCount = 0, resetTime);
            if (sCount === 2) {
                window.scrollBy(0, window.innerHeight);
                sCount = 0;
            }
        }
    });
})();