Hentaizap Full Gallery Loader

Load all pages in the reader vertically

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

You will need to install an extension such as Tampermonkey 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.

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