bili_rebuild

b站评论过滤器

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name bili_rebuild
// @description b站评论过滤器
// @license MIT
// @namespace dreamcenter
// @version 2.1.0.2
// @match *://*.bilibili.com/video/*
// @match *://*.bilibili.com/opus/*
// @match *://space.bilibili.com/*/dynamic
// @grant GM_xmlhttpRequest
// ==/UserScript==


/*******************************下方内容可以修改***************************************/
let banMap = [
    'test','随机','恶心','病','纯','ch','CH','op','策划'
];
// 等级可选项: level_0/level_1/level_2/level_3/level_4/level_5/level_6/level_h  其中h表示的是加闪电的六级号
let banLevel = [
    'level_0'
]


/*******************************下方内容不要修改***************************************/

function judgeIfBanned(raw) {
    for(var key of banMap) {
        if (raw.includes(key)) return true;
    }
    return false;
}

function judgeIfLevelBanned(levelImg) {
    for(var key of banLevel) {
        if (levelImg.includes(key)) return true;
    }
    return false;
}

(function() {
    'use strict';
    window.onload=function(){

        var startMark = false

        setInterval(function(){
            // 判断是否可以开始执行核心程序
            if (startMark){
                runCore();
            } else {
                // 判断节点是否渲染完毕
                startMark = document.querySelector("bili-comments") != null
            }
        },100)
    }



    function runCore (){
        // 获取整楼评论
        var reviews = document.querySelector("bili-comments").shadowRoot.querySelectorAll("#feed > bili-comment-thread-renderer");
        for(var review of reviews){
            // 判断该元素是否为null(可能元素还没渲染出来)

            // 检查楼主评论是否过滤过,过滤则不再计算
            if (review.getAttribute('filtered') == null){
                // 获取楼主评论
                var comment = review.shadowRoot.querySelector('#comment')
                // 获取楼主Lv等级
                var level = comment.shadowRoot.querySelector("#header > bili-comment-user-info").shadowRoot.querySelector("#user-level > img").src
                // 获取楼主评论内容
                var commentText = comment.shadowRoot.querySelector("#content > bili-rich-text").shadowRoot.querySelector("#contents").innerHTML;
                // 状态设置成已经过滤判断过
                review.setAttribute('filtered',true)
                // 过滤判断
                if(judgeIfLevelBanned(level) || judgeIfBanned(commentText)) {
                    review.style.display = "none";
                }
            }

            // 获取回复评论集
            var replies = review.shadowRoot.querySelector("#replies > bili-comment-replies-renderer").shadowRoot.querySelectorAll("#expander-contents > bili-comment-reply-renderer:not([filtered])")
            for(var reply of replies) {
                // 获取回复评论Lv等级
                var replyLevel = reply.shadowRoot.querySelector("#main > bili-comment-user-info").shadowRoot.querySelector("#user-level > img").src
                // 获取回复评论内容
                var replyCommentText = reply.shadowRoot.querySelector("#main > bili-rich-text").shadowRoot.querySelector("#contents").innerHTML;
                // 状态设置成已经过滤判断过
                reply.setAttribute('filtered',true)
                // 过滤判断
                if(judgeIfLevelBanned(replyLevel) || judgeIfBanned(replyCommentText)) {
                    reply.style.display = "none";
                }
            }
        }
    }

})();