iThome Arrow Key Pager

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

目前為 2019-12-03 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         iThome Arrow Key Pager
// @namespace    https://github.com/livinginpurple
// @version      2019.12.03.01
// @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/*
// @include 	 *
// @run-at       document-end
// @grant        none
// @grant        GM.xmlHttpRequest
// ==/UserScript==

(function() {
    'use strict';
    console.log(GM_info.script.name + " is loading.");
    const newerPager = document.getElementsByClassName("article-series-page__link")[0];
    const olderPager = document.getElementsByClassName("article-series-page__link")[1];

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