Comic viewer restore

Show comic, removes the upsell overlay, and restores page scrolling.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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               Comic viewer restore
// @namespace          https://greasyfork.org/users/821661
// @version            0.2.1
// @description        Show comic, removes the upsell overlay, and restores page scrolling.
// @author             hdyzen
// @match              https://www.gocomics.com/*
// @run-at             document-start
// @icon               https://www.google.com/s2/favicons?domain=www.gocomics.com
// @grant              none
// @license            MIT
// @noframes
// ==/UserScript==

const comics = new Map();

Response.prototype.json = new Proxy(Response.prototype.json, {
    async apply(target, thisArg, argArray) {
        const result = await Reflect.apply(target, thisArg, argArray);

        const isArray = Array.isArray(result);
        if (isArray && result[0]?.url) {
            comics.set(location.pathname, result[0]);
        }

        return result;
    },
});

const observer = new MutationObserver(() => {
    const comicViewer = document.querySelector('[class*="showComicViewer__skeleton"]:not([data-processed])');
    if (!comicViewer) return;

    const comic = comics.get(location.pathname);
    if (!comic) return;
    comicViewer.dataset.processed = true;

    observer.disconnect();
    comicViewer.innerHTML = `<img class="comic-image" src="${comics.get(location.pathname)?.url}">`;
    observer.observe(document.documentElement, { childList: true, subtree: true });
});

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

const style = document.createElement("style");
style.textContent = `
    [class*='upsell'] { display: none !important }
    html, body { overflow: auto !important; position: initial !important }
    .comic-image { background-color: #1f1b19; }
    `;
document.documentElement.append(style);