iThome Arrow Key Pager

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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