大佬论坛换回减白主题油猴脚本

菜鸡鲲 (UID: 698) 1天前 [复制链接]
帖子链接已复制到剪贴板
帖子已经有人评论啦,不支持删除!

325 7
// ==UserScript==
// @name         大佬论坛换回减白主题油猴脚本
// @namespace    https://www.dalao.net/
// @version      1.1
// @description  替换 dalao.net 的 anhui.css 为 jianbai.css
// @author       https://www.dalao.net/
// @match        https://www.dalao.net/*
// @match        https://dalao.net/*
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';
    const targetCss = 'https://www.dalao.net/plugin/hehe_theme_laguo/view/css/jianbai.css';
    const preload = document.createElement('link');
    preload.rel = 'stylesheet';
    preload.href = targetCss;
    document.documentElement.appendChild(preload);
    const originalAppendChild = Element.prototype.appendChild;
    Element.prototype.appendChild = function (element) {
        if (
            element.tagName === 'LINK' &&
            element.rel === 'stylesheet' &&
            element.href &&
            /anhui\.css(\?[^]*)?$/.test(element.href)
        ) {
            console.log('[Tampermonkey] 拦截并替换 anhui.css → jianbai.css');
            element.href = element.href.replace(/anhui\.css(\?[^]*)?$/, 'jianbai.css');
        }
        return originalAppendChild.call(this, element);
    };
    const observer = new MutationObserver(() => {
        const links = document.querySelectorAll('link[rel="stylesheet"]');
        links.forEach(link => {
            if (link.href && /anhui\.css(\?[^]*)?$/.test(link.href)) {
                console.log('[Tampermonkey] 动态替换已存在的 anhui.css');
                link.href = link.href.replace(/anhui\.css(\?[^]*)?$/, 'jianbai.css');
            }
        });
    });
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();

 

我是超级无敌大鲨臂,谁敢反对?
已有评论 ( 7 )
提示:您必须 登录 才能查看此内容。
创建新帖
广告推广点击空位自助购买TG联系