rfc page turning key

rfc page turning key: ← →

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         rfc page turning key
// @namespace    http://note.yurenchen.com/archives/js_snippets.html
// @version      0.1
// @description  rfc page turning key: ← →
// @author       yurenchen
// @match        https://tools.ietf.org/html/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    //rfc page turning key: ← →
    var pages = document.getElementsByClassName('newpage');
    var page_height = pages[1].offsetTop-pages[0].offsetTop;
    console.log('page_height"', page_height);
    function nextpage(){
        document.body.scrollTop += page_height;
    }
    function prevpage(){
        document.body.scrollTop -= page_height;
    }
    document.body.onkeydown = function(e){
        console.log('onkeydown:',e);
        switch(e.key){
        case 'ArrowRight':
            nextpage();
            break;
        case 'ArrowLeft':
            prevpage();
            break;
        }
    };

})();