[银河奶牛]强化模拟网页助手

重定向 jQuery 库请求

// ==UserScript==
// @name         [银河奶牛]强化模拟网页助手
// @namespace    http://tampermonkey.net/
// @version      1.02
// @description  重定向 jQuery 库请求
// @match        https://doh-nuts.github.io/*
// @license      Truth_Light
// @grant        GM_xmlhttpRequest
// @connect      cdn.jsdelivr.net
// ==/UserScript==

(function() {
    const originalUrl = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js";
    const newUrl = "https//code.jquery.com/jquery-3.7.1.min.js";
    GM_xmlhttpRequest({
        method: "GET",
        url: newUrl,
        onload: function(response) {
            if (response.status === 200) {
                const script = document.createElement('script');
                script.textContent = response.responseText;
                document.head.appendChild(script);
            } else {
                fallbackToOriginal();
            }
        },
        onerror: function() {
            fallbackToOriginal();
        }
    });

    function fallbackToOriginal() {
        GM_xmlhttpRequest({
            method: "GET",
            url: originalUrl,
            onload: function(response) {
                if (response.status === 200) {
                    const script = document.createElement('script');
                    script.textContent = response.responseText;
                    document.head.appendChild(script);
                }
            }
        });
    }
})();