Hentaizap Full Gallery Loader

Load all pages in the reader vertically

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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.');
    });
})();