Rawkuma Image Downloader

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

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

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

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

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

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