nhentai Auto Scroller

Auto scroll doujinshi and manga on nhentai so you can jerk off all hands-free.

คุณจะต้องติดตั้งส่วนขยาย เช่น 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         nhentai Auto Scroller
// @namespace    http://tampermonkey.net/
// @version      2.0.0
// @description  Auto scroll doujinshi and manga on nhentai so you can jerk off all hands-free.
// @author       LoliEnjoyer
// @include      /^https:\/\/nhentai\.net\/g\/\d+\/\d+\/$/
// ==/UserScript==

const ScrollHandler = {
    scrollIntervalID: null,
    turnPageIntervalID: null,

    startReader() {
        const scrollDelay = 5; // Increase this value to make scrolling slower. Default nhentai value: 5
        const scrollSpeed = 1;
        const scrollLimit = document.body.scrollHeight - window.innerHeight;

        if (this.scrollIntervalID === null) {
            this.scrollIntervalID = setInterval(() => {
                let scrollPos = window.scrollY;
                if (scrollPos < scrollLimit) {
                    window.scrollTo(0, scrollPos + scrollSpeed);
                } else {
                    clearInterval(this.scrollIntervalID);
                    this.scrollIntervalID = null;
                    this.turnPage(4500);
                }
            }, scrollDelay);
        }
    },

    stopReader() {
        clearInterval(this.scrollIntervalID);
        clearInterval(this.turnPageIntervalID);
        this.scrollIntervalID = null;
        this.turnPageIntervalID = null;
    },

    turnPage(timeout) {
        if (this.turnPageIntervalID === null) {
            this.turnPageIntervalID = setInterval(() => { unsafeWindow.reader.next_page() }, timeout);
        }
    }
};

let isAutoScroll = false;
let scrollTimeoutID = null;

const div = document.createElement('div');
const button = document.createElement('button');
const icon = document.createElement('i');
button.setAttribute('class', 'btn btn-primary');
icon.setAttribute('class', 'fa fa-lg fa-play');
div.setAttribute('style', 'z-index: 100; right: 0; margin: 10px;')
button.setAttribute('style', 'width: 46px; height: 46px;')

function buttonClickAction() {
    isAutoScroll = !isAutoScroll;
    icon.setAttribute('class', `fa fa-lg ${isAutoScroll ? 'fa-pause' : 'fa-play'}`);
    if (isAutoScroll) {
        ScrollHandler.startReader();
    } else {
        ScrollHandler.stopReader();
        clearTimeout(scrollTimeoutID);
        scrollTimeoutID = null;
    }
}

function buttonPosition() {
    window.scrollY >= 90
        ? Object.assign(div.style, { position: 'fixed', top: 0 })
        : Object.assign(div.style, { position: 'absolute', top: "90px" });
}

buttonPosition();
button.appendChild(icon);
div.appendChild(button);
document.body.appendChild(div);

button.addEventListener('click', buttonClickAction);
window.addEventListener('scroll', buttonPosition);

new MutationObserver(() => {
    if (isAutoScroll) {
        ScrollHandler.stopReader();
        clearTimeout(scrollTimeoutID);
        scrollTimeoutID = setTimeout(() => {
            ScrollHandler.startReader();
            scrollTimeoutID = null;
        }, 3000);
    }
}).observe(document.body, { childList: true, subtree: true });