禁用CSDN背景

禁用CSDN背景,防止动态背景导致CPU占用过高

Mint 2023.08.15.. Lásd a legutóbbi verzió

// ==UserScript==
// @name         禁用CSDN背景
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  禁用CSDN背景,防止动态背景导致CPU占用过高
// @author       vertexz、ChatGPT
// @match        https://blog.csdn.net/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=csdn.net
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var style = document.createElement('style');
    style.innerHTML = `
    * {
        animation: none !important;
        transition: none !important;
    }
    body {
        background-image: none !important;
    }
    `;
    document.head.appendChild(style);

    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            var addedNodes = mutation.addedNodes;
            for (var i = 0; i < addedNodes.length; i++) {
                var node = addedNodes[i];
                if (node.getAttribute != undefined && node.getAttribute("style") != null && node.getAttribute("style").includes("animation")) {
                    node.style.animation = "none";
                }
                if (node.getAttribute != undefined && node.getAttribute("style") != null && node.getAttribute("style").includes("transition")) {
                    node.style.transition = "none";
                }
            }
        });
    });

    observer.observe(document.documentElement, {childList: true, subtree: true});
})();