// ==UserScript== // @name B站评论区过滤 // @namespace http://tampermonkey.net/ // @version 0.1.6 // @description 正则过滤B站评论 // @author _Gliese_ // @match *://*.bilibili.com/* // @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js // @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js // @require https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js // @require https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js // @run-at document-body // @grant GM_getResourceText // @grant GM_setValue // @grant GM_getValue // @downloadURL https://update.greasyfork.icu/scripts/432454/B%E7%AB%99%E8%AF%84%E8%AE%BA%E5%8C%BA%E8%BF%87%E6%BB%A4.user.js // @updateURL https://update.greasyfork.icu/scripts/432454/B%E7%AB%99%E8%AF%84%E8%AE%BA%E5%8C%BA%E8%BF%87%E6%BB%A4.meta.js // ==/UserScript== (function() { // Your code here... const configItems = ['filter-regex'] let userConfig = {} const getConfig = () => { // 获取配置 configItems.forEach(item => { let text = GM_getValue(item) if(text){ $('#comment-filter-form #' + item).val(text) userConfig[item] = text } }) } const setConfig = (config) => { configItems.forEach(item => { GM_setValue(item, config[item]) userConfig[item] = config[item] }) } const filterMain = () => { // 过滤主楼评论 let hasConfig = userConfig['filter-regex'] && userConfig['filter-regex'] !== '' let mainNodes = $('.comment-list .list-item') for(let i = 0; i < mainNodes.length; ++i) { let commentItem = mainNodes[i] let commentText = commentItem.children[1].children[1].innerText if(commentText.search(new RegExp(userConfig['filter-regex'])) !== -1 && hasConfig) { // 匹配成功,将主楼设置为不可见 commentItem.style.display = 'none' } else { // 设置为可见(防止过滤字符改变后某些楼需要显示) commentItem.style.display = '' } } } const filter = () => { // 调用过滤操作 filterMain() } const mount = () => { // 初始化 let style = ` ` $('head') .append(style) let form = `
正则屏蔽: