Hentaizap Full Gallery Loader

Load all pages in the reader vertically

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Hentaizap Full Gallery Loader
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Load all pages in the reader vertically
// @author       Orgacord
// @match        *://*.hentaizap.com/g/*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function waitFor(selector, timeout = 5000) {
        return new Promise((resolve, reject) => {
            const start = Date.now();
            const timer = setInterval(() => {
                const el = document.querySelector(selector);
                if (el) {
                    clearInterval(timer);
                    resolve(el);
                } else if (Date.now() - start > timeout) {
                    clearInterval(timer);
                    reject();
                }
            }, 50);
        });
    }

    Promise.all([
        waitFor('#pages'),
        waitFor('#fimg'),
        waitFor('.mid_rd')
    ]).then(([pagesEl, baseImg, mainContainer]) => {
        const totalPages = parseInt(pagesEl.value, 10);
        if (!totalPages) return;

        const baseUrl = baseImg.dataset.src || baseImg.src;
        const match = baseUrl.match(/^(.*\/)(\d+)(\.\w+)$/);
        if (!match) return;

        const [, basePath, , ext] = match;

        mainContainer.innerHTML = '';

        const style = document.createElement('style');
        style.textContent = `
            .gm-full-view {
                display: flex;
                flex-direction: column;
                align-items: center;
                background: #1a1a1a;
                padding: 20px 0;
                gap: 15px;
            }
            .gm-full-view img {
                max-width: 100%;
                height: auto;
                display: block;
                box-shadow: 0 0 10px rgba(0,0,0,0.5);
            }
            .reader_overlay, .fw_img { display: none !important; }
        `;
        document.head.appendChild(style);

        const fullViewDiv = document.createElement('div');
        fullViewDiv.className = 'gm-full-view';
        mainContainer.appendChild(fullViewDiv);

        for (let i = 1; i <= totalPages; i++) {
            const img = document.createElement('img');
            img.loading = 'lazy';
            img.decoding = 'async';
            img.alt = `Page ${i}`;
            img.src = `${basePath}${i}${ext}`;

            img.onerror = () => {
                if (ext !== '.jpg') {
                    img.src = `${basePath}${i}.jpg`;
                } else {
                    img.remove();
                }
            };

            fullViewDiv.appendChild(img);
        }

        console.log(`Loaded ${totalPages} pages.`);
    }).catch(() => {
        console.warn('Gallery loader: required elements not found.');
    });
})();