MangaPark Image Fix

Fix broken images on Park/Manga sites without breaking lazy loading

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

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

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

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

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

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

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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

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

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

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         MangaPark Image Fix
// @namespace    park-sites-image-fix
// @version      1.0
// @description  Fix broken images on Park/Manga sites without breaking lazy loading
// @match        *://mangapark.com/*
// @match        *://mangapark.net/*
// @match        *://mangapark.org/*
// @match        *://mangapark.me/*
// @match        *://mangapark.io/*
// @match        *://mangapark.to/*
// @match        *://comicpark.org/*
// @match        *://comicpark.to/*
// @match        *://readpark.org/*
// @match        *://readpark.net/*
// @match        *://parkmanga.com/*
// @match        *://parkmanga.net/*
// @match        *://parkmanga.org/*
// @match        *://mpark.to/*
// @run-at       document-idle
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const processed = new WeakSet();

    function fixImages() {
        const base = location.protocol + "//" + location.host;
        const imgs = document.getElementsByTagName("img");

        for (let i = 0; i < imgs.length; i++) {
            const img = imgs[i];
            if (processed.has(img)) continue;

            const src = img.getAttribute("src");
            if (!src) continue;

            if (src.indexOf("//s") !== -1 && src.indexOf(".") !== -1) {
                try {
                    const p = src.split("//")[1];
                    const fixed = base + p.substring(p.indexOf("/"));
                    img.src = fixed;
                    processed.add(img);
                } catch (e) {}
            }
        }
    }

    // Initial run
    fixImages();

    // Observe dynamic image loading
    const observer = new MutationObserver(() => {
        fixImages();
    });

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