Hentaizap Full Gallery Loader

Load all pages in the reader vertically

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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