禁用CSDN动态背景

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         禁用CSDN动态背景
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  禁用CSDN动态背景,防止CPU占用过高
// @author       离尘zh、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 hasAnimatedBackground = false;
    try {
        var element = document.querySelector('body');
        var styles = window.getComputedStyle(element);
        if (styles.backgroundImage.indexOf(".gif") !== -1) {
            hasAnimatedBackground = true;
        }
    } catch (e) {}

    if (hasAnimatedBackground) {
        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;
                addedNodes.forEach(function (node) {
                    if (node.nodeType !== Node.ELEMENT_NODE) {
                        return;
                    }

                    var nodeStyle = node.getAttribute("style");
                    if (nodeStyle != null) {
                        if (nodeStyle.includes("animation")) {
                            node.style.animation = "none";
                        }
                        if (nodeStyle.includes("transition")) {
                            node.style.transition = "none";
                        }
                    }

                    var bgStyle = node.style.backgroundImage;
                    if (bgStyle.indexOf(".gif") !== -1) {
                        node.style.backgroundImage = "none";
                    }
                });
            });
        });

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

})();