Greasy Fork is available in English.

预加载下一章/页,方向键上/下一章

try to take over the world!

// ==UserScript==
// @name         预加载下一章/页,方向键上/下一章
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       wodexianghua
// @match        http://*/*
// @match        https://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    document.addEventListener('keydown', function (event) {
        if (document.activeElement.nodeName != 'BODY') { return; }
        var shang = false;
        var xia = false;
        var tf = false;
        var searchText;
        var searchText2;

        if (event.keyCode == 37) {
            shang = true;
            searchText = '上一章';
            searchText2 = '上一页';
        } else if (event.keyCode == 39) {
            xia = true;
            searchText = '下一章';
            searchText2 = '下一页';
        }

        if (document.body.innerText.includes(searchText) || document.body.innerText.includes(searchText2)) {
            tf = true;
        }

        if (tf) {
            var aTags = document.getElementsByTagName("a");
            var found;

            for (var i = 0; i < aTags.length; i++) {
                if (aTags[i].textContent.includes(searchText)) {
                    found = aTags[i];
                    break;
                }
            }
            if (found == undefined) {
                for (var i = 0; i < aTags.length; i++) {
                    if (aTags[i].textContent.includes(searchText2)) {
                        found = aTags[i];
                        break;
                    }
                }
            }
            found.click();
        }
    });

    setTimeout(() => {
        if (document.body.innerText.includes('下一章') || document.body.innerText.includes('下一页')) {

            let aTags = document.getElementsByTagName("a");
            let found;

            for (var i = 0; i < aTags.length; i++) {
                if (aTags[i].textContent.includes('下一章')) {
                    found = aTags[i];
                    break;
                }
            }
            if (found == undefined) {
                for (var i = 0; i < aTags.length; i++) {
                    if (aTags[i].textContent.includes('下一页')) {
                        found = aTags[i];
                        break;
                    }
                }
            }
            let xia = found.getAttribute('href');
            if (!xia.includes(document.domain)) {
                var ishttps = 'https:' == document.location.protocol ? true : false;
                if (ishttps) {
                    xia = 'https://' + document.domain + '' + xia;
                } else {
                    xia = 'http://' + document.domain + '' + xia;
                }
            }
            var head = document.querySelector('head');
            head.insertAdjacentHTML('beforeend', '<link rel="prefetch" href="' + xia + '" />');
        }
    }, 500);
    // Your code here...
})();