Greasy Fork is available in English.

iThome Arrow Key Pager

使用方向鍵前往上一頁(←)、下一頁(→)

// ==UserScript==
// @name         iThome Arrow Key Pager
// @namespace    https://github.com/livinginpurple
// @version      2019.12.03.12
// @description  iThome Arrow Key Pager - Use ← (Go to Previous Page), → (Go to Next Page)
// @description:zh-TW   使用方向鍵前往上一頁(←)、下一頁(→)
// @license      WTFPL
// @author       livinginpurple
// @match        https://ithelp.ithome.com.tw/*
// @run-at       document-end
// @grant        none
// @grant        GM.xmlHttpRequest
// ==/UserScript==

(function () {
    'use strict';
    console.log(GM_info.script.name + " is loading.");
    const previousPage = document.getElementsByClassName("fa fa-fw fa-angle-left")[0];
    const nextPage = document.getElementsByClassName("fa fa-fw fa-angle-right")[0];

    document.addEventListener('keydown', (event) => {
        let keyName = event.key;
        //console.log('keydown event\n\n' + 'key: ' + keyName);
        if ((event.altKey && (keyName === "ArrowLeft" || keyName === "ArrowRight"))) {
            return false;
        }
        if (keyName === "ArrowRight") {
            if (nextPage === undefined || nextPage === null) {
                alert("Last Page!!");
                return false;
            }
            nextPage.click();
        }
        if (keyName === "ArrowLeft") {
            if (previousPage === undefined || previousPage === null) {
                alert("First Page!!");
                return false;
            }
            previousPage.click();
        }
    });
    console.log(GM_info.script.name + " is running.");
})(document);