Greasy Fork

Greasy Fork is available in English.

Yanmaga Manga Completo Captura + ZIP

Captura las imágenes completas del manga en yanmaga.jp y permite descargarlas como ZIP.

当前为 2025-06-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         Yanmaga Manga Completo Captura + ZIP
// @namespace    yanmaga-fullpage
// @version      1.5
// @description  Captura las imágenes completas del manga en yanmaga.jp y permite descargarlas como ZIP.
// @author       
// @license      MIT
// @match        https://yanmaga.jp/viewer/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const imagenesCapturadas = [];

    function esperarCargarPagina() {
        const candidatas = document.querySelectorAll('img');
        if (candidatas.length === 0) return setTimeout(esperarCargarPagina, 500);

        const btn = document.createElement('button');
        btn.textContent = '📸 Capturar Páginas Manga';
        Object.assign(btn.style, {
            position: 'fixed',
            top: '10px',
            left: '10px',
            zIndex: 9999,
            background: '#1f2937',
            color: 'white',
            padding: '10px 14px',
            borderRadius: '6px',
            border: 'none',
            fontSize: '14px',
            cursor: 'pointer'
        });
        btn.onclick = capturarPaginasManga;
        document.body.appendChild(btn);
    }

    async function capturarPaginasManga() {
        const imagenes = [...document.querySelectorAll('img')];
        const imagenesManga = imagenes.filter(img => img.naturalHeight >= 800 && img.naturalWidth >= 500 && !img.src.includes('icon'));

        for (let i = 0; i < imagenesManga.length; i++) {
            const img = imagenesManga[i];
            const url = img.src;
            if (!url || imagenesCapturadas.find(x => x.url === url)) continue;

            const blob = await fetch(url).then(r => r.blob());
            const bitmap = await createImageBitmap(blob);
            const width = bitmap.width;
            const height = bitmap.height;
            const nombre = `pagina_${String(imagenesCapturadas.length + 1).padStart(3, '0')}_${width}x${height}.jpg`;
            imagenesCapturadas.push({ blob, fileName: nombre, url });

            mostrarMiniatura(nombre, url);
        }

        mostrarBotonDescarga();
        alert(`✅ Capturadas ${imagenesCapturadas.length} páginas completas`);
    }

    function mostrarMiniatura(nombre, url) {
        let panel = document.getElementById('galeria-panel');
        if (!panel) {
            panel = document.createElement('div');
            panel.id = 'galeria-panel';
            Object.assign(panel.style, {
                position: 'fixed',
                top: '60px',
                left: '10px',
                width: '300px',
                maxHeight: '80vh',
                overflowY: 'auto',
                background: '#f8fafc',
                border: '2px solid #111',
                padding: '10px',
                zIndex: 9998,
                fontSize: '12px'
            });
            panel.innerHTML = `<strong>Galería:</strong><div id="lista-imagenes" style="margin-top:10px; display:flex; flex-direction:column; gap:6px;"></div>`;
            document.body.appendChild(panel);
        }

        const contenedor = document.getElementById('lista-imagenes');
        const item = document.createElement('div');
        item.innerHTML = `
            <img src="${url}" style="width:100%; border:1px solid #ccc;" />
            <span>${nombre}</span>
        `;
        contenedor.appendChild(item);
    }

    function mostrarBotonDescarga() {
        if (document.getElementById('descargar-zip')) return;

        const btn = document.createElement('button');
        btn.id = 'descargar-zip';
        btn.textContent = '⬇️ Descargar ZIP';
        Object.assign(btn.style, {
            marginTop: '10px',
            width: '100%',
            padding: '8px',
            background: '#16a34a',
            color: 'white',
            border: 'none',
            borderRadius: '4px',
            cursor: 'pointer'
        });
        btn.onclick = descargarZIP;
        document.getElementById('galeria-panel').appendChild(btn);
    }

    async function descargarZIP() {
        const zip = new JSZip();
        for (const img of imagenesCapturadas) {
            zip.file(img.fileName, img.blob);
        }
        const contenido = await zip.generateAsync({ type: 'blob' });
        saveAs(contenido, 'yanmaga_manga_completo.zip');
        alert('📦 ZIP descargado con éxito');
    }

    esperarCargarPagina();
})();