E-Hentai Infinite Scroll

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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.

You will need to install a user script manager extension to install this script.

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

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