☰

nhentai Page Changer

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

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu budete musieť nainštalovať rozšírenie, ako je napríklad Tampermonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==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;
        }
    };
})();