HITOMI GALLERY PAGE LOADER

script for loading pages inside galleries on hitomi.la

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         HITOMI GALLERY PAGE LOADER
// @namespace    https://greasyfork.org
// @version      2024-10-06
// @description  script for loading pages inside galleries on hitomi.la
// @author       qwertybot
// @match        https://hitomi.la/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
let pageNum = 1;
let intervalId;
let isPaused = false;
let isCodeExecuted = false;


if (window.location.href.endsWith('.html#1')) {

    function createOriginalThumbnailContainer() {
        let originalThumbnailList = document.querySelector('ul.thumbnail-list');


        let originalContainer = document.createElement('div');
        originalContainer.appendChild(originalThumbnailList.cloneNode(true));


        document.querySelector('div.simplePagerContainer').appendChild(originalContainer);
    }


    function loadNextPage() {
        if (isPaused) return;


        let nextPageSelector = 'li.simplePageNav' + (pageNum + 1) + ' a';
        let nextLink = document.querySelector(nextPageSelector);


        if (nextLink) {

            nextLink.click();


            pageNum++;


            setTimeout(() => {

                let newThumbnailList = document.querySelector('ul.thumbnail-list');


                if (newThumbnailList) {

                    let galleryContainer = document.createElement('div');
                    galleryContainer.appendChild(newThumbnailList.cloneNode(true));


                    document.querySelector('div.simplePagerContainer').appendChild(galleryContainer);
                }
            }, 1000);
        } else {
            console.log('No next page. Hide original thumbnail-list and stop.');
            document.querySelector('ul.thumbnail-list').style.display = 'none';
            clearInterval(intervalId);
        }
    }


    function togglePause() {
        isPaused = !isPaused;
        const pauseButton = document.getElementById('pause-button');
        pauseButton.innerText = isPaused ? 'Continue' : 'Pause';
    }


    function createPauseButton() {
        const pauseButton = document.createElement('button');
        pauseButton.id = 'pause-button';
        pauseButton.innerText = 'Pause';
        pauseButton.style.position = 'fixed';
        pauseButton.style.top = '10px';
        pauseButton.style.right = '10px';
        pauseButton.style.zIndex = '9999';
        pauseButton.style.padding = '10px 15px';
        pauseButton.style.backgroundColor = '#ff5722';
        pauseButton.style.color = '#fff';
        pauseButton.style.border = 'none';
        pauseButton.style.borderRadius = '5px';
        pauseButton.style.cursor = 'pointer';
        pauseButton.addEventListener('click', togglePause);
        document.body.appendChild(pauseButton);
    }


    createOriginalThumbnailContainer();
    createPauseButton();


    isCodeExecuted = true;


    intervalId = setInterval(loadNextPage, 1500);
} else {
    console.log('Wrong page, script on pause.');
}
})();