Mangalib Infinite Scroll

Infinite scroll on chat mangalib.me

Verze ze dne 12. 06. 2019. Zobrazit nejnovější verzi.

// ==UserScript==
// @name         Mangalib Infinite Scroll
// @version      0.7.1
// @description  Infinite scroll on chat mangalib.me
// @author       reiwsan
// @match        https://mangalib.me/*
// @match        https://ranobelib.me/*
// @namespace    https://greatest.deepsurf.us/users/221048
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const preloadPos = 753;

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

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

        chatItems.addEventListener('scroll', _ => {
            let scrollPos = (chatItems.scrollHeight - chatItems.scrollTop);
            let 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);

                let chatItems = document.querySelector('.chat__items');
                historyAutoload(chatItems, chatMore);
            }
        }, 50);
    }
})();