Comick Docs Fix

Replaces all instances of api.comick.fun with api.comick.dev and intercepts API calls

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Comick Docs Fix
// @namespace    https://github.com/GooglyBlox
// @version      1.0
// @description  Replaces all instances of api.comick.fun with api.comick.dev and intercepts API calls
// @author       GooglyBlox
// @match        https://api.comick.dev/docs*
// @grant        none
// @license      MIT
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const originalFetch = window.fetch;
    window.fetch = function(...args) {
        if (args[0] && typeof args[0] === 'string') {
            args[0] = args[0].replace(/api\.comick\.fun/g, 'api.comick.dev');
        } else if (args[0] && args[0].url) {
            args[0].url = args[0].url.replace(/api\.comick\.fun/g, 'api.comick.dev');
        }
        return originalFetch.apply(this, args);
    };

    const originalOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url, ...rest) {
        if (typeof url === 'string') {
            url = url.replace(/api\.comick\.fun/g, 'api.comick.dev');
        }
        return originalOpen.call(this, method, url, ...rest);
    };

    function replaceURLs(node) {
        if (node.nodeType === Node.TEXT_NODE) {
            const originalText = node.textContent;
            const replacedText = originalText
                .replace(/https:\/\/api\.comick\.fun/g, 'https://api.comick.dev')
                .replace(/api\.comick\.fun/g, 'api.comick.dev');
            if (originalText !== replacedText) {
                node.textContent = replacedText;
            }
        } else if (node.nodeType === Node.ELEMENT_NODE) {
            if (node.tagName !== 'SCRIPT' && node.tagName !== 'STYLE') {
                for (let child of node.childNodes) {
                    replaceURLs(child);
                }
            }

            if (node.hasAttribute('href')) {
                const href = node.getAttribute('href');
                if (href.includes('api.comick.fun')) {
                    node.setAttribute('href', href.replace(/api\.comick\.fun/g, 'api.comick.dev'));
                }
            }

            if (node.hasAttribute('src')) {
                const src = node.getAttribute('src');
                if (src.includes('api.comick.fun')) {
                    node.setAttribute('src', src.replace(/api\.comick\.fun/g, 'api.comick.dev'));
                }
            }
        }
    }

    function processPage() {
        replaceURLs(document.body);
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', processPage);
    } else {
        processPage();
    }

    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.TEXT_NODE) {
                    replaceURLs(node);
                }
            });
        });
    });

    if (document.body) {
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    } else {
        document.addEventListener('DOMContentLoaded', function() {
            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    }
})();