Greasy Fork is available in English.

隐藏Bilibili侧边栏话题

隐藏Bilibili侧边栏话题,没找到这个功能的脚本,自己编着玩的

// ==UserScript==
// @name         隐藏Bilibili侧边栏话题
// @version      0.0.2
// @namespace    http://tampermonkey.net/
// @description  隐藏Bilibili侧边栏话题,没找到这个功能的脚本,自己编着玩的
// @author       Xw
// @match           *://*.bilibili.com/*
// @exclude         *://api.bilibili.com/*
// @exclude         *://api.*.bilibili.com/*
// @exclude         *://*.bilibili.com/api/*
// @exclude         *://member.bilibili.com/studio/bs-editor/*
// @exclude         *://t.bilibili.com/h5/dynamic/specification
// @exclude         *://bbq.bilibili.com/*
// @exclude         *://message.bilibili.com/pages/nav/header_sync
// @exclude         *://s1.hdslb.com/bfs/seed/jinkela/short/cols/iframe.html
// @exclude         *://open-live.bilibili.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const interval = setInterval(() => {
        if (mainFunc()) {
            clearInterval(interval);
            console.log('执行隐藏侧边栏话题脚本完成');
        }
    }, 500);
})();

function mainFunc() {
    let isShow = 0;
    const elements = document.querySelectorAll('.relevant-topic-container');
    if (! elements || elements.length === 0) return false;
    showOrHideElements(elements, isShow);

    // 添加开关按钮
    const navElement = document.querySelector('.topic-panel__nav');
    if(navElement) {
        const button = document.createElement('button');
        button.textContent = '展开';
        button.style.border = 'none';
        button.style.backgroundColor = 'white';
        button.style.color = '#00aeec';
        button.style.fontSize = '16px';
        button.style.fontWeight = '600';

        button.addEventListener('click', () => {
            if(isShow === 0) {
                isShow = 1;
                button.textContent = '折叠';
            } else {
                isShow = 0;
                button.textContent = '展开';
            }
            showOrHideElements(elements, isShow);
        });

        navElement.appendChild(button);
    }
    return true;
}

/**
    显示或隐藏元素
    type:
        1: 显示
        0: 隐藏
**/
function showOrHideElements(elements, type) {
    if(elements) {
        elements.forEach(element => {
            if(type === 1) {
                element.style.display = 'block';
            } else if (type === 0) {
                element.style.display = 'none';
            }
        });
    }
}