Manatoki468 Direct Downloader (Fix HQ Images)

Descarga imágenes en alta calidad de capítulos de manga desde Manatoki468 directamente.

// ==UserScript==
// @name         Manatoki468 Direct Downloader (Fix HQ Images)
// @namespace    shadows
// @version      1.5.3
// @description  Descarga imágenes en alta calidad de capítulos de manga desde Manatoki468 directamente.
// @author       shadows
// @license      MIT
// @match        https://manatoki468.net/*
// @grant        GM_download
// ==/UserScript==

"use strict";

(function () {
    const downloadButton = document.createElement("button");
    downloadButton.textContent = "Descargar imágenes HQ";
    downloadButton.style = `
        position: fixed;
        top: 10px;
        right: 10px;
        z-index: 10000;
        background-color: #007bff;
        color: white;
        border: none;
        padding: 10px 20px;
        font-size: 14px;
        border-radius: 5px;
        cursor: pointer;
    `;
    document.body.appendChild(downloadButton);

    downloadButton.addEventListener("click", async () => {
        // Capturar todas las imágenes visibles que estén dentro de los contenedores de lectura de manga
        const imageElements = Array.from(document.querySelectorAll("img"));

        // Extraer la URL de la imagen real (alta calidad)
        const imageUrls = imageElements
            .map(img => img.getAttribute("data-src") || img.getAttribute("src"))
            .filter(url => url && url.includes("/comic/") && !url.includes("thumb"))
            .map(url => {
                // Asegurar que no sean miniaturas (pueden tener parámetros ?resize=...)
                return url.split("?")[0];
            });

        if (imageUrls.length === 0) {
            alert("No se encontraron imágenes del manga para descargar.");
            return;
        }

        for (const [index, url] of imageUrls.entries()) {
            const fileName = `${String(index + 1).padStart(3, "0")}.jpg`;
            try {
                await downloadImage(url, fileName);
                console.log(`Descargada: ${fileName}`);
            } catch (err) {
                console.error(`Error al descargar ${fileName}:`, err);
            }
        }

        alert(`Se descargaron ${imageUrls.length} imágenes correctamente.`);
    });

    function downloadImage(url, fileName) {
        return new Promise((resolve, reject) => {
            GM_download({
                url: url,
                name: fileName,
                headers: {
                    Referer: "https://manatoki468.net/"
                },
                onload: () => resolve(),
                onerror: (err) => reject(err),
            });
        });
    }
})();