Greasy Fork

来自缓存

Greasy Fork is available in English.

屏蔽博客园和CSDN动态背景

移除博客园和CSDN页面上的动态背景和特效

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         屏蔽博客园和CSDN动态背景
// @namespace    https://www.cnblogs.com/
// @version      0.4
// @description  移除博客园和CSDN页面上的动态背景和特效
// @author       yakoye
// @match        *://*.cnblogs.com/*
// @match        https://blog.csdn.net/*
// @grant        none
// @license MIT
// ==/UserScript==

// 测试网页 CSDN: https://blog.csdn.net/m0_63574813/article/details/130313383
//        博客园:https://www.cnblogs.com/brady-wang/p/10565156.html
(function() {
    'use strict';

    console.log("Tampermonkey script loaded");

    // Function to remove the particle effect scripts and canvases on cnblogs
    function removeParticleEffects() {
        // Get all script elements
        var scripts = document.getElementsByTagName('script');

        // Iterate over the script elements
        for (var i = 0; i < scripts.length; i++) {
            var script = scripts[i];

            // Check if the script contains particle effect initialization
            if (script.src.includes("particles.min.js") || script.innerHTML.includes("particlesJS")) {
                script.remove();
                console.log("Removed particle effect script:", script);
            }
        }

        // Remove canvas elements related to particle effects
        var canvases = document.getElementsByTagName('canvas');
        for (var j = 0; j < canvases.length; j++) {
            var canvas = canvases[j];
            canvas.remove();
            console.log("Removed canvas element:", canvas);
        }
    }

    // Function to remove the dynamic background images on CSDN
    function removeCSDNBackground() {
        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
            });
        }
    }

    // Detect if the site is CSDN or cnblogs and run the respective function
    if (window.location.host.indexOf('cnblogs.com') > -1) {
        console.log("Running script for cnblogs");
        // Run the function to remove particle effects
        removeParticleEffects();

        // Observe for added scripts dynamically
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes.length) {
                    removeParticleEffects();
                }
            });
        });

        // Observe changes in the document
        observer.observe(document.documentElement, { childList: true, subtree: true });

    } else if (window.location.host.indexOf('csdn.net') > -1) {
        console.log("Running script for csdn");
        // Run the function to remove CSDN background
        removeCSDNBackground();
    }

})();