SH Arrow Key Next/Prev Chapter

Navigate to the next / previous chapter on right / left arrow keys on ScribbleHub.

当前为 2021-03-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SH Arrow Key Next/Prev Chapter
// @namespace    ultrabenosaurus.ScribbleHub
// @version      0.3
// @description  Navigate to the next / previous chapter on right / left arrow keys on ScribbleHub.
// @author       Ultrabenosaurus
// @source       https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
// @match        https://www.scribblehub.com/read/*/chapter/*
// @icon         https://www.google.com/s2/favicons?domain=scribblehub.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var consoleTitle = "SH Arrow Key Next/Prev Chapter:";

    document.onkeyup = function(e){
        e = e || window.event;
        var prevSelector = "div.next_nav_links a.btn-wi.btn-prev";
        var prevAnchorText = "Previous";
        var nextSelector = "div.next_nav_links a.btn-wi.btn-next";
        var nextAnchorText = "Next";

        //console.log(consoleTitle, e);

        var commentBox = document.querySelectorAll('div#comment_placeholder.comment_placeholder');
        var commentEditBox = document.querySelectorAll('div.cmt_edit_chp');
        if( ( commentBox.length > 0 && e.target == commentBox[0] ) || ( commentEditBox.length > 0 && e.target == commentEditBox[0] ) ) {
            console.info(consoleTitle, "Matched a comment box, aborting chapter navigation.");

            e = prevSelector = prevAnchorText = nextSelector = nextAnchorText = commentBox = null;
            return;
        }

        if( e.keyCode == '37' ) {
            // left arrow
            e.preventDefault();
            var pLink = document.querySelectorAll(prevSelector);
            if( pLink.length == 0 ) {
                console.error(consoleTitle, "No links found for query selctor: '"+prevSelector+"'");
                return null;
            }
            if( pLink[0].textContent.search(prevAnchorText) >= 0 ) {
                console.info(consoleTitle, "Navigating to previous chapter:", pLink[0].href);
                pLink[0].click();
            } else {
                console.error(consoleTitle, "Link in position 0 did not contain text: '"+prevAnchorText+"'");
            }
            pLink = null;
        } else if( e.keyCode == '39' ) {
            // right arrow
            e.preventDefault();
            var nLink = document.querySelectorAll(nextSelector);
            if( nLink.length == 0 ) {
                console.error(consoleTitle, "No links found for query selctor: '"+nextSelector+"'");
                return null;
            }
            if( nLink[0].textContent.search(nextAnchorText) >= 0 ) {
                console.info(consoleTitle, "Navigating to next chapter:", nLink[0].href);
                nLink[0].click();
            } else {
                console.error(consoleTitle, "Link in position 0 did not contain text: '"+nextAnchorText+"'");
            }
            nLink = null;
        }

        e = prevSelector = prevAnchorText = nextSelector = nextAnchorText = commentBox = null;
    };
})();