E-Hentai Infinite Scroll

Auto load next image. Free your hand from keyboard/mouse.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         E-Hentai Infinite Scroll
// @namespace    http://e-hentai.org/
// @version      0.1
// @description  Auto load next image. Free your hand from keyboard/mouse.
// @author       Bill.code
// @match        https://e-hentai.org/s/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const displayArea = document.querySelector('#i3');
    let page = document;
    let lock = false;
    document.addEventListener('scroll', checkAndLoad, {passive: true});
    checkAndLoad();

    async function checkAndLoad() {
        if (document.body.clientHeight - window.scrollY < window.innerHeight * 4 && !lock) {
            lock = true;
            page = await loadPage(page);
            lock = false;
            console.log(page);
        }
    }
    function loadPage(dom) /* Promise<HTMLDocument>: the document of next page */ {
        const nextPageA = dom.querySelector('#next');
        if (!nextPageA) return;

        return fetch(nextPageA.href)
        .then(e => e.text())
        .then(rawHtml => {
            const parser = new DOMParser();
            const newDom = parser.parseFromString(rawHtml, 'text/html');
            displayArea.appendChild(newDom.querySelector('#i3 img'));
            return newDom;
        });
    }
})();