Infinite Scroll

Infinite scrolling for March 2019 layout redesign.

Versione datata 15/05/2019. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Infinite Scroll
// @author       Hauffen
// @description  Infinite scrolling for March 2019 layout redesign.
// @version      1.96
// @include      /https?:\/\/(e-|ex)hentai\.org\/.*/
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @namespace    https://greasyfork.org/users/285675
// ==/UserScript==

(function() {
    var url = document.URL;
    var page = 0;
    var query, nextUrl;
    var index = document.getElementsByTagName("select").length > 1 ? 1 : 0;

    function newUrl() {
        if (url.match(/f_shash/)) {
            return null;
        }

        if (url.split('?').length > 1) {
            if (!$.isNumeric(url.split('?')[1].substr(5,1))) {
                if (url.indexOf('&') > 0 ) {
                    query = url.substr(url.indexOf('&'));
                } else {
                    query = url.split('?')[1];
                }
            } else {
                page = url.split('?')[1].substr(5,1);
            }
            nextUrl = (query != null) ? "https://" + window.location.hostname + "/?page=" + (page + 1) + "&" + query : "https://" + window.location.hostname + "/?page=" + (page + 1);

            if (page > 0 && $.isNumeric(url.split('?')[1].substr(5,1))) {
                query = url.substr(url.indexOf("&"));
                nextUrl = (query != null) ? "https://" + window.location.hostname + "/?page=" + (page + 1) + "&" + query : "https://" + window.location.hostname + "/?page=" + (page + 1);
            }
        } else if (url.match(/\Dtag\D/)) {
            if ((page + 2) > $(".ptt tr")[0].children[$(".ptt tr")[0].children.length - 2].children[0].text) {
                nextUrl = null;
            } else {
                nextUrl = url + "/" + (page + 1);
            }
        } else {
            nextUrl = "https://" + window.location.hostname + "/?page=" + (page + 1);
        }
    };

    newUrl();

    function loadMore(){
        if (url.split('/')[3] === "g" || url.split('/')[3] === "s") {
            return;
        }

        if ($(window).scrollTop() + $(window).height() >= $(document).height() && nextUrl != null) {
            var offset = "&from=" + document.getElementsByClassName('itg')[0].lastChild.getElementsByTagName("a")[0].href.split("/")[4];
            var $content = $('<div>');
            $content.load(url.match(/\Dtag\D/) ? nextUrl :`${nextUrl + offset}`, function() {
                var divs = null;

                if (window.location.hostname.substr(1,1) !== "x") {
                    if (document.getElementsByTagName("select")[index].selectedIndex == 3) {
                        divs = this.getElementsByClassName('itg')[0].childrenn;
                    } else {
                        divs = this.getElementsByClassName('itg')[0].children;
                    }
                } else {
                    if (document.getElementsByTagName("select")[index].selectedIndex == 4) {
                        divs = this.getElementsByClassName('itg')[0].children;
                    } else {
                        divs = this.getElementsByClassName('itg')[0].children[0].children;
                    }
                }

                if (document.getElementsByTagName("select")[index].selectedIndex !== 3 && document.getElementsByTagName("select")[index].selectedIndex !== 4) {
                    divs[0].parentNode.removeChild(divs[0]);
                }

                while (divs.length > 0) {
                    $('.itg').append(divs[0]);
                };
            });

            page++;
            newUrl();
        }
    };

    if ($("body").height() < $(window).height()) {
        loadMore();
    }

    $(window).on('scroll', function(){
        loadMore();
    });
})();