删除Bilibili上被广告插件拦截的内容

删除bilibili主页被广告插件拦截的内容

11.08.2024 itibariyledir. En son verisyonu görün.

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

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 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         删除Bilibili上被广告插件拦截的内容
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  删除bilibili主页被广告插件拦截的内容
// @match        https://www.bilibili.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function removeSpecificDivs() {
        // 处理被feed-card包裹的情况
        const feedCards = document.querySelectorAll('.feed-card');
        feedCards.forEach(card => {
            const videoCard = card.querySelector('.bili-video-card.is-rcmd');
            if (videoCard && !videoCard.classList.contains('enable-no-interest')) {
                card.remove();
            }
        });

        // 处理直接的bili-video-card
        const directVideoCards = document.querySelectorAll('.bili-video-card.is-rcmd:not(.enable-no-interest)');
        directVideoCards.forEach(card => {
            // 如果父元素不是feed-card,直接删除这个bili-video-card
            if (!card.parentElement.classList.contains('feed-card')) {
                card.remove();
            }
        });
    }

    // 初始执行
    removeSpecificDivs();

    // 创建一个MutationObserver来监视DOM变化
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.type === 'childList') {
                removeSpecificDivs();
            }
        });
    });

    // 配置观察选项
    const config = { childList: true, subtree: true };

    // 开始观察文档主体
    observer.observe(document.body, config);
})();