nhentai Page Changer

Allows to change page with keyboard arrows in results /search pages

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         nhentai Page Changer
// @namespace    http://tampermonkey.net/
// @version      0.5.7
// @description  Allows to change page with keyboard arrows in results /search pages
// @author       You
// @match        https://nhentai.net/search/*
// @include      https://nhentai.net/*
// @grant        none
// ==/UserScript==

(function () {
    "use strict";
    // Your code here...
    window.onkeydown = function (e) {
        var origURL = document.URL;
        var num;
        var prenum;
        var newUrl;
        function getNum() {
            var counter = 1;
            do {
                prenum = origURL.charAt(origURL.length - counter - 1);
                console.log(origURL);
                console.log("prenum: " + prenum);
                console.log(prenum.match(/[0-9]+/g));
                if (prenum.match(/[0-9]+/g)) {
                    counter++;
                }
            } while (prenum.match(/[0-9]+/g));

            return counter;
        }

        var code = e.keyCode ? e.keyCode : e.which;
        if (code === 39) {
            //right key
            if (origURL.includes("page")) {
                if (
                    document.URL.includes("page") &&
                    !document.URL.charAt(document.URL.length - 1).match(/[1-9]/)
                ) {
                    var regx = /(&page=[0-9]+)/g;
                    var match;
                    match = regx.exec(this.document.URL);
                    var index1 = match.index;
                    var index2 = match[0].length;
                    this.console.log(`index 1: ${index1} y index 2: ${index2}`);
                    this.console.log(this.document.URL.substr(index1,index2));
                    var array1 = origURL.split(/(&page=[0-9]+)/g);
                    this.console.log(array1);
                    var temp = array1[2];
                    array1[2] = array1[1];
                    array1[1] = temp;
                    origURL = array1.join("");
                }
                var counter = getNum();
                console.log("counter: " + counter);
                num = origURL.substring(origURL.length - counter, origURL.length);
                num++;
                newUrl = origURL.substring(0, origURL.length - counter);
                newUrl = newUrl.concat(num);
                window.location = newUrl;
            }
            else if (origURL.match(/^.*nhentai.net\/g\/[0-9]*\/$/)){
                window.location = origURL.concat("1/");
            }else if (origURL.match(/.*nhentai.net\/g\/[0-9]*\//)){
                return;
            }
            else if (origURL.includes("tag") || origURL == "https://nhentai.net/") {
                newUrl = origURL;
                newUrl = newUrl.concat("?page=2");
                window.location = newUrl;
            }
            else if (!origURL.includes("page")) {
                newUrl = origURL.substring(0, origURL.length - 1);
                newUrl = newUrl.concat("&page=2");
                window.location = newUrl;
            }
        } else if (code === 37 && !origURL.match(/.*nhentai.net\/g\/[0-9]*\//)) {
            //left key
            counter = getNum();
            console.log(counter);
            num = origURL.substring(origURL.length - counter, origURL.length);
            console.log(num);
            num--;
            newUrl = origURL.substring(0, origURL.length - counter);
            newUrl = newUrl.concat(num);
            window.location = newUrl;
        }
    };
})();