Rawkuma Image Downloader

Downloads all chapter images from rawkuma.net as individual files.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Rawkuma Image Downloader
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Downloads all chapter images from rawkuma.net as individual files.
// @author       Baconana-chan
// @match        https://rawkuma.net/manga/*/chapter-*
// @grant        GM_xmlhttpRequest
// @connect      rcdn.kyut.dev
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Find the chapter title for naming the files
    let titleElem = document.querySelector('.font-semibold.text-gray-50.text-sm.flex.items-center.content-center');
    let chapterTitle = titleElem ? titleElem.textContent.trim().replace(/[\\/:*?"<>|]/g, '_') : 'chapter';

    // Find the image section
    let imageSection = document.querySelector('section[data-image-data="1"]');
    if (!imageSection) {
        console.error('Image section not found.');
        alert('Image section not found on the page.');
        return;
    }

    // Get all image elements
    let images = imageSection.querySelectorAll('img');
    if (images.length === 0) {
        console.error('No images found in the section.');
        alert('No images found in the chapter.');
        return;
    }

    // Create a download button
    let button = document.createElement('button');
    button.textContent = 'Download All Images';
    button.style.position = 'fixed';
    button.style.top = '10px';
    button.style.right = '10px';
    button.style.zIndex = '9999';
    button.style.padding = '10px 20px';
    button.style.backgroundColor = '#4CAF50';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.fontSize = '16px';
    document.body.appendChild(button);

    button.addEventListener('click', () => {
        let urls = Array.from(images).map(img => img.src);
        let loadedImages = 0;

        // Download each image with a slight delay to avoid overwhelming the browser
        urls.forEach((url, index) => {
            setTimeout(() => {
                GM_xmlhttpRequest({
                    method: 'GET',
                    url: url,
                    responseType: 'blob',
                    headers: {
                        'Referer': window.location.href
                    },
                    onload: function(response) {
                        if (response.status === 200) {
                            let filename = `${chapterTitle}_${String(index + 1).padStart(3, '0')}.jpg`;
                            let link = document.createElement('a');
                            link.href = URL.createObjectURL(response.response);
                            link.download = filename;
                            document.body.appendChild(link);
                            link.click();
                            document.body.removeChild(link);
                            console.log(`Downloaded image ${filename}`);
                            loadedImages++;
                            if (loadedImages === urls.length) {
                                alert(`All ${loadedImages} images downloaded successfully.`);
                            }
                        } else {
                            console.error(`Failed to load image ${url}: Status ${response.status}`);
                            if (index === urls.length - 1) {
                                alert(`Downloaded ${loadedImages} out of ${urls.length} images. Check console for details.`);
                            }
                        }
                    },
                    onerror: function(error) {
                        console.error(`Error fetching image ${url}:`, error);
                        if (index === urls.length - 1) {
                            alert(`Downloaded ${loadedImages} out of ${urls.length} images. Check console for details.`);
                        }
                    }
                });
            }, index * 1000); // Delay of 1 second between downloads
        });
    });
})();