Greasy Fork

Greasy Fork is available in English.

Descargar imágenes de Comic Earthstar

Detecta y descarga todas las imágenes cargadas como blobs en Comic Earthstar

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Descargar imágenes de Comic Earthstar
// @namespace    https://comic-earthstar.com/
// @version      1.1
// @description  Detecta y descarga todas las imágenes cargadas como blobs en Comic Earthstar
// @author       TuNombre
// @match        https://comic-earthstar.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Crear un contenedor para almacenar las URLs detectadas
    const detectedURLs = new Set();

    // Crear un botón para iniciar la descarga
    const downloadButton = document.createElement('button');
    downloadButton.innerText = 'Descargar imágenes';
    downloadButton.style.position = 'fixed';
    downloadButton.style.top = '10px';
    downloadButton.style.right = '10px';
    downloadButton.style.zIndex = '9999';
    downloadButton.style.padding = '10px';
    downloadButton.style.backgroundColor = '#007bff';
    downloadButton.style.color = 'white';
    downloadButton.style.border = 'none';
    downloadButton.style.borderRadius = '5px';
    downloadButton.style.cursor = 'pointer';
    document.body.appendChild(downloadButton);

    // Función para interceptar peticiones de red
    const observeNetworkRequests = () => {
        const originalOpen = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function (...args) {
            this.addEventListener('load', function () {
                if (this.responseURL.startsWith('blob:https://comic-earthstar.com')) {
                    detectedURLs.add(this.responseURL);
                }
            });
            originalOpen.apply(this, args);
        };

        const originalFetch = window.fetch;
        window.fetch = async function (...args) {
            const response = await originalFetch(...args);
            if (response.url.startsWith('blob:https://comic-earthstar.com')) {
                detectedURLs.add(response.url);
            }
            return response;
        };
    };

    // Función para observar cambios en el DOM y detectar blobs
    const observeDOMChanges = () => {
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList') {
                    const images = Array.from(document.querySelectorAll('img[src^="blob:https://comic-earthstar.com"]'));
                    images.forEach((img) => detectedURLs.add(img.src));
                }
            });
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
        });
    };

    // Función para descargar las imágenes
    async function downloadImages() {
        if (detectedURLs.size === 0) {
            alert('No se detectaron imágenes para descargar.');
            return;
        }

        let counter = 1;
        for (const blobUrl of detectedURLs) {
            try {
                const blob = await fetch(blobUrl).then((res) => res.blob());
                const link = document.createElement('a');
                const url = URL.createObjectURL(blob);

                link.href = url;
                link.download = `imagen_${String(counter).padStart(3, '0')}.png`;
                link.click();

                // Liberar el objeto URL temporal
                URL.revokeObjectURL(url);
                counter++;
            } catch (error) {
                console.error('Error descargando la imagen:', blobUrl, error);
            }
        }

        alert('Descarga completa.');
    }

    // Asignar la función de descarga al botón
    downloadButton.addEventListener('click', downloadImages);

    // Iniciar la observación de peticiones de red y cambios en el DOM
    observeNetworkRequests();
    observeDOMChanges();
})();