Mangalib Infinite Scroll

Infinite scroll on chat mangalib.me

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

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

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         Mangalib Infinite Scroll
// @version      0.7.3
// @description  Infinite scroll on chat mangalib.me
// @author       reiwsan
// @match        https://mangalib.me/*
// @match        https://ranobelib.me/*
// @namespace    https://greasyfork.org/users/221048
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const preloadPos = 321;

    /**
     * @param {Element} chatMore
     * @returns {void}
     */
    const historyAutoload = function(chatMore) {
        let chatItems = document.querySelector('.chat__items'),
            historyLoad = false;

        /**
         * @param {Element} chatMore
         * @returns {boolean}
         */
        const chatMoreClick = function(chatMore) {
            chatMore.click();
            return true;
        }

        chatItems.addEventListener('scroll', _ => {
            let scrollPos = ((chatItems.scrollHeight - chatItems.clientHeight) - chatItems.scrollTop),
                scrollPreload = (scrollPos <= preloadPos);

            historyLoad = (scrollPreload && !historyLoad) ?
                chatMoreClick(chatMore) : scrollPreload;
        });
    }

    if (typeof _CHAT_INSTANCE !== 'undefined') {
        const chatInitInterval = setInterval(() => {
            let chatMore = document.querySelector('.chat__more');

            if (chatMore) {
                clearInterval(chatInitInterval);
                historyAutoload(chatMore);
            }
        }, 50);
    }
})();