Comick Docs Fix

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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
            });
        });
    }
})();