🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

SH Arrow Key Next/Prev Chapter

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         SH Arrow Key Next/Prev Chapter
// @namespace    ultrabenosaurus.ScribbleHub
// @version      0.4
// @description  Navigate to the next / previous chapter on right / left arrow keys on ScribbleHub.
// @author       Ultrabenosaurus
// @license      GNU AGPLv3
// @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;
    };
})();