Greasy Fork 支持简体中文。

[Bilibili首页去广告]去除B站首页广告,更改样式

去除B站首页的轮播广告,小广告,直播与番剧推荐,并修改若干样式

// ==UserScript==
// @name         [Bilibili首页去广告]去除B站首页广告,更改样式
// @version      1.0.2
// @description  去除B站首页的轮播广告,小广告,直播与番剧推荐,并修改若干样式
// @author       You
// @match        https://www.bilibili.com/
// @icon         https://i0.hdslb.com/bfs/static/jinkela/long/images/favicon.ico
// @grant        none
// @namespace http://tampermonkey.net/
// ==/UserScript==

(function() {
    'use strict';

    document.querySelector('.recommended-swipe').remove()

    document.querySelector('.bili-header__channel').remove()

    document.querySelectorAll('.feed-card > :not(.enable-no-interest)').forEach(function(el){
        el.parentNode.remove()
    })

    document.querySelectorAll('.bili-video-card.is-rcmd:not(.enable-no-interest)').forEach(function(el) {
        el.remove()
    })

    document.querySelectorAll('.floor-single-card').forEach(function(el) {
        el.remove()
    })

    document.querySelectorAll('.bili-live-card').forEach(function(el) {
        el.remove()
    })

    const roolbtntimer = setInterval(function() {
        if (document.querySelector('.roll-btn') !== null) {
            document.querySelector('.roll-btn').addEventListener('click', function() {
                setInterval(function(){
                    document.querySelector('.feed-card > :not(.enable-no-interest)').parentNode.style.display = 'none'
                    const firstTenEL = document.querySelectorAll('.feed-card')
                    if (firstTenEL[4].style.display === 'none') {
                        firstTenEL[5].style.marginTop = '0'
                    }
                }, 100)
            })
            clearInterval(roolbtntimer)
        }
    }, 500)

    const cssRule = `
    .bili-header {
        margin-bottom: 40px;
    }

    .bili-header::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100px;
        background: linear-gradient(to top, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
        z-index: 1;
    }

    @media (max-width: 1400px) {
        .recommended-container_floor-aside .container>*:nth-of-type(5) {
            margin-top: 24px;
        }
    }

    .header-channel { display: none !important }

    .recommended-swipe { display: none !important; }

    .feed-card > :not(.enable-no-interest) { display: none !important; }

    .bili-video-card.is-rcmd:not(.enable-no-interest) { display: none !important; }

    .floor-single-card { display: none !important; }

    .bili-live-card { display: none !important; }

    .recommended-container_floor-aside .container>*:nth-of-type(6) {
        margin-top: 24px;
    }

    .recommended-container_floor-aside .container>*:nth-of-type(7) {
        margin-top: 24px !important;
    }

    .recommended-container_floor-aside .container>*:nth-of-type(n + 8) {
        margin-top: 24px !important;
    }

    .recommended-container_floor-aside .container.is-version8>*:nth-of-type(n + 13) {
        margin-top: 24px !important;
    }

    .recommended-container_floor-aside .container .floor-single-card:first-of-type {
        margin-top: 24px !important;
    }

    .recommended-container_floor-aside .container .load-more-anchor .floor-single-card {
        margin-top: 24px !important;
    }
    `;

    addStyleForDeleteAD(cssRule);

})();

function addStyleForDeleteAD(cssRule) {
    // 创建一个style元素
    const style = document.createElement('style');
    style.type = 'text/css';

    // 将CSS规则添加到style元素
    style.appendChild(document.createTextNode(cssRule));

    // 将style元素添加到文档的head中
    document.head.appendChild(style);
}