Force Replace main.css with mainblue.css

Replaces all references to /css/main.css with /css/mainblue.css

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Force Replace main.css with mainblue.css
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Replaces all references to /css/main.css with /css/mainblue.css
// @match        *://*/*
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // Intercept all requests for /css/main.css
    const observer = new MutationObserver(() => {
        document.querySelectorAll('link[rel="stylesheet"]').forEach(link => {
            if (link.href.includes("/css/main.css")) {
                link.href = link.href.replace("/css/main.css", "/css/mainblue.css");
            }
        });
    });

    // Watch DOM changes
    observer.observe(document.documentElement, { childList: true, subtree: true });

    // Also handle fetch() and XHR requests
    const origOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {
        if (url.includes("/css/main.css")) {
            url = url.replace("/css/main.css", "/css/mainblue.css");
        }
        return origOpen.apply(this, arguments);
    };

    // For fetch API
    const origFetch = window.fetch;
    window.fetch = function(input, init) {
        if (typeof input === "string" && input.includes("/css/main.css")) {
            input = input.replace("/css/main.css", "/css/mainblue.css");
        } else if (input.url && input.url.includes("/css/main.css")) {
            input = new Request(input.url.replace("/css/main.css", "/css/mainblue.css"), input);
        }
        return origFetch(input, init);
    };
})();