Remove CSDN

Remove CSDN from Google Search.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name                Remove CSDN
// @name:zh-CN          移除CSDN
// @description         Remove CSDN from Google Search.
// @description:zh-CN   移除谷歌搜索中的CSDN。
// @namespace           https://github.com/yxzlwz/browser_scripts
// @author              yxzlwz
// @match               *://*.google.com/*
// @match               *://*.google.com.hk/*
// @run-at              document-end
// @version             1.1.0
// ==/UserScript==

(function () {
    function main(node) {
        const list = node.getElementsByTagName("a");
        for (let i = 0; i < list.length; i++) {
            const a = list[i];
            if (a.href.startsWith("https://blog.csdn.net/")) {
                let parent = a;
                for (let j = 0; j < 5; j++) {
                    parent = parent.parentElement;
                }
                if (parent) {
                    parent.style.display = "none";
                }
            }
        }
    }
    main(window.document);

    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            m.addedNodes.forEach(node => {
                if (node.nodeType === Node.ELEMENT_NODE) {
                    main(node);
                }
            });
        }
    });

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