// ==UserScript== // @name 哔哩哔哩 - 屏蔽指定内容 // @namespace https://greasyfork.org/zh-CN/users/193133-pana // @homepage https://www.sailboatweb.com // @version 3.13.0 // @description 实现可分别按用户名、关键字、正则表达式对视频(或直播间)和评论进行屏蔽; 将鼠标移至网页右下角弹出悬浮按钮 // @author pana // @include http*://www.bilibili.com/* // @include http*://search.bilibili.com/* // @include http*://live.bilibili.com/* // @include http*://space.bilibili.com/* // @require https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js // @license GNU General Public License v3.0 or later // @grant GM_getValue // @grant GM_setValue // @grant GM_setClipboard // @grant GM_registerMenuCommand // @grant GM_addValueChangeListener // @run-at document-start // @note ver.3.13.0 实现多标签页同步数据; 调整取消按钮的行为; 覆盖视频播放完毕后的推荐视频; 兼容"Bilibili 旧播放页"脚本(https://greasyfork.org/zh-CN/scripts/394296); 依旧存在的兼容问题: 在主页和视频播放页等页面下同时开启脚本时,本脚本无法保存设置到存储中 // @note ver.3.11.0 增加直播区的相关屏蔽; 覆盖个人动态内的评论; 添加展开列表按钮 // @note ver.3.7.1 添加删除按钮; 完善部分未被覆盖的页面内容 // @note ver.3.5.3 修复部分页面下输入框内容看不清以及其他小问题 // @note ver.3.5.0 优化代码; 完善部分未被覆盖的页面内容; 悬浮图标自动隐藏等 // @note ver.2.2.0 添加允许将评论中的 b 站内置表情包转换成对应文字的功能 // @note ver.2.1.2 修复储存正则表达式出错的问题; 优化代码 // @note ver.2.1.0 添加允许按正则表达式进行屏蔽的功能 // @note ver.2.0.0 调整了添加与删除关键字的方式,方便操作; 将评论与视频标题的关键词分开作用 // @note ver.1.2.1 完善部分未被覆盖的页面内容 // @note ver.1.2.0 添加屏蔽评论的功能 // @note ver.1.1.2 调整屏蔽按钮的位置到右下角; 尝试处理脚本偶尔会失效的问题 // @note ver.1.1.1 修复搜索页面以关键字屏蔽无效的问题 // @note ver.1.1.0 匹配视频播放页面; 优化代码 // @downloadURL none // ==/UserScript== (function() { 'use strict'; const OLD_URL = location.href; const CHECKBOX_VALUE = { 'START': { 'id': 'startCheckbox', 'label': '启用屏蔽功能', 'title': '总开关' }, 'VIDEO_USERNAME': { 'id': 'videoUsernameCheckbox', 'label': '按用户名', 'title': '屏蔽指定用户发布的视频(或直播间)' }, 'VIDEO_KEYWORD': { 'id': 'videoKeywordCheckbox', 'label': '按关键字', 'title': '屏蔽标题中包含指定关键字的视频(或直播间)' }, 'VIDEO_REG': { 'id': 'videoRegCheckbox', 'label': '按正则', 'title': '屏蔽标题匹配指定正则表达式的视频(或直播间)', }, 'COMMENT_USERNAME': { 'id': 'commentUsernameCheckbox', 'label': '按用户名', 'title': '屏蔽指定用户发布的评论' }, 'COMMENT_KEYWORD': { 'id': 'commentKeywordCheckbox', 'label': '按关键字', 'title': '屏蔽内容中包含指定关键字的评论' }, 'COMMENT_REG': { 'id': 'commentRegCheckbox', 'label': '按正则', 'title': '屏蔽内容匹配指定正则表达式的评论' }, 'CONVERT_EMOJI': { 'id': 'convertEmojiCheckbox', 'label': '表情转成文字', 'title': '判定时将表情包转换成对应的标识文字,例:[doge]' }, 'LIVE': { 'id': 'liveCheckbox', 'label': '扩展到直播区', 'title': '同时允许屏蔽直播间' } }; const INPUT_VALUE = { 'USERNAME': { 'id': 'usernameInput', 'label': '输入:', 'placeholder': ' 多个时以半角逗号分隔 ' }, 'VIDEO_KEYWORD': { 'id': 'videoKeywordInput', 'label': '输入:', 'placeholder': ' 多个时以半角逗号分隔 ' }, 'COMMENT_KEYWORD': { 'id': 'commentKeywordInput', 'label': '输入:', 'placeholder': ' 多个时以半角逗号分隔 ' }, 'VIDEO_REG': { 'id': 'videoRegInput', 'label': '输入:', 'placeholder': ' / 建议写成 \\/ ' }, 'VIDEO_MODIFIER': { 'id': 'videoModifierInput', 'label': '修饰符:', 'placeholder': '如:gim' }, 'COMMENT_REG': { 'id': 'commentRegInput', 'label': '输入:', 'placeholder': ' / 建议写成 \\/ ' }, 'COMMENT_MODIFIER': { 'id': 'commentModifierInput', 'label': '修饰符:', 'placeholder': '如:gim' } }; const TEXTAREA_VALUE = { 'USERNAME': { 'id': 'usernameTextarea' }, 'VIDEO_KEYWORD': { 'id': 'videoKeywordTextarea' }, 'COMMENT_KEYWORD': { 'id': 'commentKeywordTextarea' }, 'VIDEO_REG': { 'id': 'videoRegTextarea' }, 'COMMENT_REG': { 'id': 'commentRegTextarea' } }; const BUTTON_VALUE = { 'ADD': { 'className': 'input_btn', 'label': '添加', 'title': '添加内容到列表中' }, 'DELETE': { 'className': 'input_btn', 'label': '删除', 'title': '从列表中删除符合的项目' }, 'CLEAR': { 'className': 'input_btn', 'label': '清空', 'title': '清空列表' }, 'COPY': { 'className': 'input_btn', 'label': '复制', 'title': '复制列表' }, 'EXPAND': { 'className': 'input_btn', 'label': '展开', 'title': '展开列表' }, 'CANCEL': { 'className': 'user_block_button cancel_button', 'label': '取消', 'title': '关闭设置窗口' }, 'SAVE': { 'className': 'user_block_button save_button', 'label': '保存并关闭', 'title': '保存设置并关闭设置窗口' }, 'ONLY_SAVE': { 'className': 'user_block_button save_button', 'label': '仅保存', 'title': '仅保存设置' } }; const MODULE = { 'USERNAME': { 'className': 'li_username' }, 'VIDEO_KEYWORD': { 'className': 'li_video_keyword' }, 'COMMENT_KEYWORD': { 'className': 'li_comment_keyword' }, 'VIDEO_REG': { 'className': 'li_video_reg' }, 'COMMENT_REG': { 'className': 'li_comment_reg' } }; const STYLE_VALUE = ` .expand_box { bottom: 0px; height: 6vh; position: fixed; right: -6vw; transition: 0.5s; width: 12vw; z-index: 99999; } .show_expand_box { right: 0; width: 6vw; } #expandSpan { background-color: #00A1D6; border-radius: 19px; border: 1px solid #00A1D6; bottom: 1vh; color: #FFF; cursor: pointer; display: block; font-size: 13px; height: 38px; line-height: 38px; position: absolute; right: 1vw; text-align: center; width: 38px; z-index: 99999; } #expandSpan:hover { box-shadow: 0 0 5px 1px green; } #wrapDiv { background-color: #222222; border-radius: 3px; border: 1px solid #282A36; bottom: 6vh; box-shadow: 0 0 5px #282A36; color: #D3D3D3; font-size: 13px; margin: 0px; padding: 0px; position: fixed; text-align: left; transition: 0.8s; width: 480px; z-index: 99999; } .show_wrap { display: block; right: 0; } .hide_wrap { right: -490px; } #mainTag { border-radius: 3px; border: 3px groove #00A1D6; height: auto; margin: 8px; min-width: 300px; padding: 4px 9px 6px 9px; width: auto; } .ul_tag { list-style: none; padding-left: 0; } .checkbox_li { display: inline-block; } .move_right { margin-left: 15px; } .checkbox_label { cursor: pointer; vertical-align: middle; } .checkbox_input { clip: rect(0, 0, 0, 0); position: absolute; } .checkbox_input + label::before { background-color: silver; border-radius: 0.1em; color: #FFF; content: "\\a0"; display: inline-block; height: 1em; line-height: 85%; margin-right: 0.5em; text-align: center; vertical-align: 0.2em; width: 1em; } .checkbox_input:checked + label::before { background-color: #00A1D6; content: "\\2713"; } .separator_text { color: #FFB86C; margin-bottom: 2px; margin-top: 2px; } .separator_symbol { background-color: #303030; height: 2px; margin-bottom: 5px; margin-top: 5px; min-width: 400px; } .input_div { margin-top: 5px; } .user_block_input { background-color: #C0C0C0; border: 1px solid #C0C0C0; color: #000; font-size: 13px; min-height: 15px; margin-left: 5px; margin-right: 5px; padding-left: 4px; } .input_btn { background-color: #3da9cc; border-radius: 3px; border: 1px solid #73C9E5; box-shadow: 0 0 4px #73C9E5; color: #FFF; cursor: pointer; display: inline-block; min-height: 15px; line-height: normal; margin-left: 5px; text-align: center; vertical-align: bottom; white-space: nowrap; width: 30px; } .textarea_div { margin-top: 5px; } .textarea_list_div { border: 1px dotted #00A1D6; margin-top: 3px; max-height: 60px; min-height: 3px; overflow: auto; } .textarea_list_div::-webkit-scrollbar { background-color: #979797; border-radius: 5px; width: 10px; } .textarea_list_div::-webkit-scrollbar-thumb { background-color: #404040; border-radius: 5px; } .textarea_copied { color: #000; } .keyword_input { width: 150px; } .reg_input { width: 100px; } .modifier_input { width: 50px; } .child_span { background-color: #3D3D3D; border-radius: 5px; border: 1px solid #3D3D3D; display: inline-block; margin: 3px; padding: 2px; min-height: 18px; line-height: normal; } .child_text { border-right: 1px solid #A9181C; margin-right: 4px; padding-right: 4px; } .child_del { color: #A9181C; cursor: pointer; } .user_block_button { background-color: #FB7299; border-radius: 4px; border: 1px solid #FB7299; color: #FFF; cursor: pointer; margin-top: 5px; padding: 2px 4px; position: relative; min-height: 17px; line-height: normal; } .save_button { float: right; margin-right: 5px; } .cancel_button { float: left; margin-left: 5px; } .block_none { display: none !important; } .block_hidden { visibility: hidden; } .li_hide { display: none; } .textarea_expand { max-height: 720px; } `; var bilibili_config = { functionEnable: true, usernameEnable: true, keywordEnable: true, commentEnable: false, commentKeywordEnable: false, regEnable: false, commentRegEnable: false, convertEmojiEnable: false, liveEnable: false, usernameArray: [], keywordArray: [], commentArray: [], regArray: [], commentRegArray: [] }; var reg_config = { regArray: [], commentRegArray: [] }; function string_2_Array(text_string) { let temp_array = text_string.split(','); let return_array = []; for (let i = 0, l = temp_array.length; i < l; i++) { for (let j = i + 1; j < l; j++) { if (temp_array[i] === temp_array[j]) { ++i; j = i; } } return_array.push(temp_array[i]); } return return_array; } function array_2_String(text_array) { return text_array.join(','); } function compare_Reg(reg_array, reg_value) { let string_array = []; reg_array.forEach(function(item) { string_array.push(item.toString()); }); let reg_string = reg_value; return string_array.includes(reg_string); } function convert_Array(string_array) { let re_arr = []; for (let i = 0; i < string_array.length; i ++) { if (string_array[i]) { try { let new_reg = new RegExp(string_array[i].replace(/^\/|\/[a-z]*$/gi, ''), string_array[i].replace(/^\/.*\/[^a-z]*/i, '')); re_arr.push(new_reg); } catch (e) { console.error('bilibili_BLock Ver.2.1.2: The transformation contains invalid regular expressions.'); console.error(e); } } } return re_arr; } function extract_Array(list_id) { let re_arr = []; let list_dom = document.getElementById(list_id); let list_arr = list_dom.getElementsByClassName('BilibiliTextSpan'); for (let i = list_arr.length - 1; i >= 0; i --) { if (list_arr[i].title) { re_arr.push(list_arr[i].title); } else { re_arr.push(list_arr[i].textContent); } } return re_arr; } function del_Child(input_tag, list_id) { let text_value = input_tag.value; if (text_value) { let del_status = false; let text_arr = string_2_Array(text_value); let save_arr = extract_Array(list_id); text_arr.forEach(function(item) { if (save_arr.includes(item)) { let total_child = document.getElementById(list_id).getElementsByClassName('child_span'); try { document.getElementById(list_id).removeChild(total_child[total_child.length - 1 - save_arr.indexOf(item)]); del_status = true; } catch (e) { del_status = false; console.error('bilibili_BLock Ver.3.6.0: Error deleting element.'); console.error(e); } } }); if (del_status) { input_tag.value = ''; } } } function add_Child(input_tag, list_id) { let text_value = input_tag.value; if (text_value) { let text_arr = string_2_Array(text_value); let save_arr = extract_Array(list_id); text_arr.forEach(function(item) { if (! save_arr.includes(item)) { document.getElementById(list_id).insertAdjacentElement('afterbegin', create_Child(item)); } }); } input_tag.value = ''; } function del_Reg_Child(reg_input, modifier_input, list_id) { let reg_value = reg_input.value; let modifier_value = modifier_input.value; if (reg_value) { let del_status = false; try { let reg_str = new RegExp(reg_value, modifier_value); let save_arr = extract_Array(list_id); if (save_arr.includes(reg_str.toString())) { let total_child = document.getElementById(list_id).getElementsByClassName('child_span'); document.getElementById(list_id).removeChild(total_child[total_child.length - 1 - save_arr.indexOf(reg_str.toString())]); del_status = true; } } catch (e) { del_status = false; console.error('bilibili_BLock Ver.3.6.0: Invalid regular expression or error deleting element.'); console.error(e); } if (del_status) { reg_input.value = ''; modifier_input.value = ''; } } } function add_Reg_Child(reg_input, modifier_input, list_id) { let reg_value = reg_input.value; let modifier_value = modifier_input.value; if (reg_value) { try { let reg_str = new RegExp(reg_value, modifier_value); let save_arr = extract_Array(list_id); if (! save_arr.includes(reg_str.toString())) { document.getElementById(list_id).insertAdjacentElement('afterbegin', create_Child(reg_str.toString())); } reg_input.value = ''; modifier_input.value = ''; } catch (e) { console.error('bilibili_Block Ver.2.1.0: Invalid regular expression.'); console.error(e); } } } function expand_Wrap(id_value) { if (document.getElementById(id_value)) { if (document.getElementById(id_value).className == 'show_wrap') { document.getElementById(id_value).className = 'hide_wrap'; document.getElementById('expandSpan').title = '显示屏蔽设置'; } else { document.getElementById(id_value).className = 'show_wrap'; document.getElementById('expandSpan').title = '隐藏屏蔽设置'; } } } function insert_Separator(ul_node, text_value = '', li_class_name = '') { let temp_li = document.createElement('li'); if (li_class_name) { temp_li.className = li_class_name; } let temp_div = document.createElement('div'); if (text_value) { temp_div.className = 'separator_text'; temp_div.textContent = text_value; } else { temp_div.className = 'separator_symbol'; } temp_li.appendChild(temp_div); ul_node.appendChild(temp_li); } function insert_Checkbox(ul_node, li_obj, check_enable_value, margin_status = true) { let temp_li = document.createElement('li'); temp_li.className = 'checkbox_li'; if (margin_status) { temp_li.classList.add('move_right'); } let temp_input = document.createElement('input'); temp_input.type = 'checkbox'; temp_input.className = 'checkbox_input'; temp_input.id = li_obj.id; if (check_enable_value) { temp_input.checked = true; } else { temp_input.checked = false; } let temp_label = document.createElement('label'); temp_label.className = 'checkbox_label'; temp_label.setAttribute('for', li_obj.id); temp_label.textContent = li_obj.label; temp_label.title = li_obj.title; temp_li.appendChild(temp_input); temp_li.appendChild(temp_label); ul_node.appendChild(temp_li); } function insert_Input(ul_node, li_obj, list_id, li_class_name) { let temp_li = document.createElement('li'); temp_li.className = li_class_name; let temp_div = document.createElement('div'); temp_div.className = 'input_div'; temp_div.textContent = li_obj.label; let temp_input = document.createElement('input'); temp_input.id = li_obj.id; temp_input.placeholder = li_obj.placeholder; temp_input.type = 'text'; temp_input.className = 'user_block_input keyword_input'; temp_input.addEventListener('keyup', function(e) { if (e.keyCode === 13) { add_Child(temp_input, list_id); } }); let add_btn = create_Span_Btn(BUTTON_VALUE.ADD, function() { add_Child(temp_input, list_id); }); let delete_btn = create_Span_Btn(BUTTON_VALUE.DELETE, function() { del_Child(temp_input, list_id); }); let clear_btn = create_Span_Btn(BUTTON_VALUE.CLEAR, function() { document.getElementById(list_id).innerHTML = ''; }); let copy_btn = create_Span_Btn(BUTTON_VALUE.COPY, function() { GM_setClipboard(array_2_String(extract_Array(list_id))); copy_btn.classList.add('textarea_copied'); copy_btn.title = '复制完成'; }); let expand_btn = create_Span_Btn(BUTTON_VALUE.EXPAND, function() { toggle_Li(li_class_name); if (expand_btn.textContent == BUTTON_VALUE.EXPAND.label) { expand_btn.textContent = '恢复'; expand_btn.title = '收缩列表'; } else { expand_btn.textContent = BUTTON_VALUE.EXPAND.label; expand_btn.title = BUTTON_VALUE.EXPAND.title; } }); temp_div.appendChild(temp_input); temp_div.appendChild(add_btn); temp_div.appendChild(delete_btn); temp_div.appendChild(clear_btn); temp_div.appendChild(copy_btn); temp_div.appendChild(expand_btn); temp_li.appendChild(temp_div); ul_node.appendChild(temp_li); } function insert_Reg_Input(ul_node, reg_obj, modifier_obj, list_id, li_class_name) { let temp_li = document.createElement('li'); temp_li.className = li_class_name; let temp_div = document.createElement('div'); temp_div.className = 'input_div'; let reg_span = document.createElement('span'); reg_span.textContent = reg_obj.label; let reg_input = document.createElement('input'); reg_input.id = reg_obj.id; reg_input.placeholder = reg_obj.placeholder; reg_input.type = 'text'; reg_input.className = 'user_block_input reg_input'; let modifier_span = document.createElement('span'); modifier_span.textContent = modifier_obj.label; let modifier_input = document.createElement('input'); modifier_input.id = modifier_obj.id; modifier_input.placeholder = modifier_obj.placeholder; modifier_input.type = 'text'; modifier_input.className = 'user_block_input modifier_input'; let add_btn = create_Span_Btn(BUTTON_VALUE.ADD, function() { add_Reg_Child(reg_input, modifier_input, list_id); }); let delete_btn = create_Span_Btn(BUTTON_VALUE.DELETE, function() { del_Reg_Child(reg_input, modifier_input, list_id); }); let clear_btn = create_Span_Btn(BUTTON_VALUE.CLEAR, function() { document.getElementById(list_id).innerHTML = ''; }); let copy_btn = create_Span_Btn(BUTTON_VALUE.COPY, function() { GM_setClipboard(array_2_String(extract_Array(list_id))); copy_btn.classList.add('textarea_copied'); copy_btn.title = '复制完成'; }); let expand_btn = create_Span_Btn(BUTTON_VALUE.EXPAND, function() { toggle_Li(li_class_name); if (expand_btn.textContent == BUTTON_VALUE.EXPAND.label) { expand_btn.textContent = '恢复'; expand_btn.title = '收缩列表'; } else { expand_btn.textContent = BUTTON_VALUE.EXPAND.label; expand_btn.title = BUTTON_VALUE.EXPAND.title; } }); modifier_span.appendChild(modifier_input); reg_span.appendChild(reg_input); temp_div.appendChild(reg_span); temp_div.appendChild(modifier_span); temp_div.appendChild(add_btn); temp_div.appendChild(delete_btn); temp_div.appendChild(clear_btn); temp_div.appendChild(copy_btn); temp_div.appendChild(expand_btn); temp_li.appendChild(temp_div); ul_node.appendChild(temp_li); } function insert_Textarea(ul_node, li_obj, save_array, li_class_name) { let temp_li = document.createElement('li'); temp_li.className = li_class_name; let temp_div = document.createElement('div'); temp_div.className = 'textarea_div'; let list_div = document.createElement('div'); list_div.className = 'BilibiliListDiv'; list_div.id = li_obj.id; list_div.className = 'textarea_list_div'; for (let item of save_array) { if (item) { list_div.insertAdjacentElement('afterbegin', create_Child(item)); } } temp_div.appendChild(list_div); temp_li.appendChild(temp_div); ul_node.appendChild(temp_li); } function create_Span_Btn(value_obj, callback) { let temp_span = document.createElement('span'); temp_span.className = value_obj.className; temp_span.textContent = value_obj.label; temp_span.title = value_obj.title; temp_span.addEventListener('click', function(e) { callback(e); }, false); return temp_span; } function create_Child(text_value) { let temp_span = document.createElement('span'); temp_span.className = 'child_span'; let text_span = document.createElement('span'); text_span.className = 'BilibiliTextSpan child_text'; text_span.textContent = (text_value.length > 9 ? text_value.slice(0, 3) + '...' + text_value.slice(-3) : text_value); if (text_value.length > 9) { text_span.title = text_value; } let del_span = document.createElement('span'); del_span.textContent = 'X'; del_span.title = '移除'; del_span.className = 'child_del'; del_span.addEventListener('click', function() { temp_span.parentNode.removeChild(temp_span); }); temp_span.appendChild(text_span); temp_span.appendChild(del_span); return temp_span; } function toggle_Li(li_class_name) { for (let li of document.querySelectorAll('ul.ul_tag li')) { if (li.classList.contains(li_class_name)) { if (li.querySelector('.textarea_list_div')) { let textarea = li.querySelector('.textarea_list_div'); if (textarea.classList.contains('textarea_expand')) { textarea.classList.remove('textarea_expand'); } else { textarea.classList.add('textarea_expand'); } } } else { if (li.classList.contains('li_hide')) { li.classList.remove('li_hide'); } else { li.classList.add('li_hide'); } } } } function decide_Text(text_value, is_comment = false, is_live = false) { if (bilibili_config.functionEnable && text_value) { if (is_comment) { if (bilibili_config.commentKeywordEnable) { for (let i of bilibili_config.commentArray) { if (i && text_value.indexOf(i) !== -1) { return true; } } } if (bilibili_config.commentRegEnable) { try { for (let j of reg_config.commentRegArray) { if (j.test(text_value)) { return true; } } } catch (e) { console.error('bilibili_BLock Ver.2.1.0: Invalid regular expression for comparison.'); console.error(e); return false; } } } else if (is_live) { if (bilibili_config.liveEnable) { if (bilibili_config.keywordEnable) { for (let k of bilibili_config.keywordArray) { if (k && text_value.indexOf(k) !== -1) { return true; } } } if (bilibili_config.regEnable) { try { for (let l of reg_config.regArray) { if (l.test(text_value)) { return true; } } } catch (e) { console.error('bilibili_BLock Ver.2.1.0: Invalid regular expression for comparison.'); console.error(e); return false; } } } } else { if (bilibili_config.keywordEnable) { for (let k of bilibili_config.keywordArray) { if (k && text_value.indexOf(k) !== -1) { return true; } } } if (bilibili_config.regEnable) { try { for (let l of reg_config.regArray) { if (l.test(text_value)) { return true; } } } catch (e) { console.error('bilibili_BLock Ver.2.1.0: Invalid regular expression for comparison.'); console.error(e); return false; } } } } return false; } function decide_Username(username, is_comment = false, is_live = false) { if (bilibili_config.functionEnable && username) { if (is_comment) { if (bilibili_config.commentEnable) { if (bilibili_config.usernameArray.includes(username)) { return true; } } } else if (is_live) { if (bilibili_config.liveEnable) { if (bilibili_config.usernameEnable) { if (bilibili_config.usernameArray.includes(username)) { return true; } } } } else { if (bilibili_config.usernameEnable) { if (bilibili_config.usernameArray.includes(username)) { return true; } } } } return false; } function hide_Operation(node, hide_status, method = 0) { if (hide_status) { if (method === 0) { node.classList.add('block_none'); } else if (method === 1) { node.classList.add('block_hidden'); } else if (method === 2) { node.style.display = 'none'; } else if (method === 3) { node.style.visibility = 'hidden'; } } else { if (method === 0) { node.classList.remove('block_none'); } else if (method === 1) { node.classList.remove('block_hidden'); } else if (method === 2) { node.style.display = ''; } else if (method === 3) { node.style.visibility = ''; } } } function hide_Handle(item_node, username, text_value, method = 0, is_comment = false, is_live = false) { if (username) { if (typeof(username) === 'object') { username = username.textContent; } } if (text_value) { if (typeof(text_value) === 'object') { text_value = text_value.textContent; } } let hide_status = false; if (decide_Username(username, is_comment, is_live)) { hide_status = true; } else if (decide_Text(text_value, is_comment, is_live)) { hide_status = true; } else { hide_status = false; } if (item_node.constructor == Array) { for (let ele_node of item_node) { hide_Operation(ele_node, hide_status, method); } } else { hide_Operation(item_node, hide_status, method); } } function hide_Event() { if (OLD_URL.indexOf('www.bilibili.com') !== -1) { let video_common_card = document.getElementsByClassName('video-card-common'); for (let video_common_card_item of video_common_card) { let username = ''; if (video_common_card_item.querySelector('a.up')) { username = video_common_card_item.querySelector('a.up').textContent.replace(/\s+$/i, ''); } if (video_common_card_item.querySelector('a.ex-up')) { username = video_common_card_item.querySelector('a.ex-up').textContent.replace(/\s+$/i, ''); } let text_value = ''; if (video_common_card_item.querySelector('a.title')) { text_value = video_common_card_item.querySelector('a.title'); } if (video_common_card_item.querySelector('p.ex-title')) { text_value = video_common_card_item.querySelector('p.ex-title'); } hide_Handle(video_common_card_item, username, text_value, 1); } let video_card_reco = document.getElementsByClassName('video-card-reco'); for (let video_card_reco_item of video_card_reco) { let username = ''; if (video_card_reco_item.querySelector('p.up')) { username = video_card_reco_item.querySelector('p.up').textContent.replace(/\s+$/i, ''); } hide_Handle(video_card_reco_item, username, video_card_reco_item.querySelector('p.title')); } let van_slide = document.querySelectorAll('.van-slide div.item'); for (let van_slide_item of van_slide) { hide_Handle(van_slide_item, '', van_slide_item.querySelector('p.title')); } let rank_wrap = document.getElementsByClassName('rank-wrap'); for (let rank_wrap_item of rank_wrap) { let text_value = ''; if (rank_wrap_item.querySelector('p.f-title')) { text_value = rank_wrap_item.querySelector('p.f-title'); } if (rank_wrap_item.querySelector('p.title')) { text_value = rank_wrap_item.querySelector('p.title'); } if (rank_wrap_item.querySelector('div.txt a.link p')) { text_value = rank_wrap_item.querySelector('div.txt a.link p'); } hide_Handle(rank_wrap_item, rank_wrap_item.querySelector('span.name'), text_value); } let article_card = document.getElementsByClassName('article-card'); for (let article_card_item of article_card) { hide_Handle(article_card_item, article_card_item.querySelector('a.up'), article_card_item.querySelector('a.title'), 1); } let live_card = document.getElementsByClassName('live-card'); for (let live_card_item of live_card) { hide_Handle(live_card_item, live_card_item.querySelector('p.name'), live_card_item.querySelector('p.desc'), 1, false, true); } let card_live_module = document.getElementsByClassName('card-live-module'); for (let card_live_module_item of card_live_module) { hide_Handle(card_live_module_item, card_live_module_item.querySelector('.auther'), card_live_module_item.querySelector('p.t'), 1, false, true); } let live_rank = document.getElementsByClassName('live-rank-item'); for (let live_rank_item of live_rank) { hide_Handle(live_rank_item, live_rank_item.querySelector('div.txt > p'), live_rank_item.querySelector('p.p2'), 0, false, true); } let manga_card = document.getElementsByClassName('manga-card'); for (let manga_card_item of manga_card) { hide_Handle(manga_card_item, '', manga_card_item.querySelector('p.manga-title'), 1); } let spread_module = document.getElementsByClassName('spread-module'); for (let spread_module_item of spread_module) { hide_Handle(spread_module_item, '', spread_module_item.querySelector('p.t')); } let groom_module = document.getElementsByClassName('groom-module'); for (let groom_module_item of groom_module) { let username = ''; if (groom_module_item.querySelector('p.author')) { username = groom_module_item.querySelector('p.author').textContent.replace(/^up主:|\s+$/i, ''); } hide_Handle(groom_module_item, username, groom_module_item.querySelector('p.title')); } try { let carousel_module_panel = document.querySelector('.carousel-module .panel'); if (carousel_module_panel) { let carousel_module_panel_title = carousel_module_panel.querySelectorAll('ul.title a'); let carousel_module_panel_pic = carousel_module_panel.querySelectorAll('ul.pic li'); let carousel_module_panel_trig = carousel_module_panel.querySelectorAll('ul.trig span'); for (let panel_index = 0; panel_index < carousel_module_panel_title.length; panel_index ++) { hide_Handle([ carousel_module_panel_title[panel_index], carousel_module_panel_pic[panel_index], carousel_module_panel_trig[panel_index] ], '', carousel_module_panel_title[panel_index], 3); } } } catch (e) { console.error('bilibili_BLock Ver.3.7.0: Variable carousel_module_panel is error.'); console.error(e); } let rank_item = document.getElementsByClassName('rank-item'); for (let rank_item_ele of rank_item) { let text_value = ''; if (rank_item_ele.querySelector('p.ri-title')) { text_value = rank_item_ele.querySelector('p.ri-title'); } if (rank_item_ele.querySelector('a.title')) { text_value = rank_item_ele.querySelector('a.title'); } hide_Handle(rank_item_ele, rank_item_ele.querySelector('.detail > a'), text_value); } let recent_hot = document.querySelectorAll('div#recent_hot li'); for (let recent_hot_item of recent_hot) { hide_Handle(recent_hot_item, '', recent_hot_item.title); } let vd_list = document.querySelectorAll('ul.vd-list li'); for (let vd_list_item of vd_list) { hide_Handle(vd_list_item, vd_list_item.querySelector('a.v-author'), vd_list_item.querySelector('a.title')); } let video_page_card = document.getElementsByClassName('video-page-card'); for (let video_page_card_item of video_page_card) { hide_Handle(video_page_card_item, video_page_card_item.querySelector('div.up'), video_page_card_item.querySelector('a.title')); } let bilibili_player_recommend_video = document.getElementsByClassName('bilibili-player-recommend-video'); for (let bilibili_player_recommend_video_item of bilibili_player_recommend_video) { hide_Handle(bilibili_player_recommend_video_item, null, bilibili_player_recommend_video_item.querySelector('.bilibili-player-recommend-title')); } let bilibili_player_ending_panel_box_recommend = document.querySelectorAll('a.bilibili-player-ending-panel-box-recommend'); for (let bilibili_player_ending_panel_box_recommend_item of bilibili_player_ending_panel_box_recommend) { hide_Handle(bilibili_player_ending_panel_box_recommend_item, null, bilibili_player_ending_panel_box_recommend_item.querySelector('.bilibili-player-ending-panel-box-recommend-cover-title')); } let read_rank_list = document.querySelectorAll('.rank-list li.item'); for (let read_rank_list_item of read_rank_list) { hide_Handle(read_rank_list_item, '', read_rank_list_item.querySelector('> a')); } if (OLD_URL.indexOf('www.bilibili.com/video/') !== -1) { hide_Comment(); } if (OLD_URL.indexOf('www.bilibili.com/read/ranking')) { let article_list = document.querySelectorAll('.article-list li'); for (let article_list_item of article_list) { hide_Handle(article_list_item, article_list_item.querySelector('.nick-name'), article_list_item.querySelector('.article-title')); } } } else if (OLD_URL.indexOf('search.bilibili.com') !== -1) { let video_item = document.getElementsByClassName('video-item'); for (let video_item_ele of video_item) { hide_Handle(video_item_ele, video_item_ele.querySelector('a.up-name'), video_item_ele.querySelector('a.title')); } } else if (OLD_URL.indexOf('live.bilibili.com') !== -1) { let rank_item = document.getElementsByClassName('rank-item'); for (let rank_item_ele of rank_item) { hide_Handle(rank_item_ele, rank_item_ele.querySelector('.room-anchor'), rank_item_ele.querySelector('.room-title'), 0, false, true); } let room_crad_wrapper= document.getElementsByClassName('room-card-wrapper'); for (let room_crad_wrapper_item of room_crad_wrapper) { hide_Handle(room_crad_wrapper_item, room_crad_wrapper_item.querySelector('.room-anchor > span'), room_crad_wrapper_item.querySelector('.room-title'), 0, false, true); } let ysly_room_ctnr = document.querySelectorAll('.ysly-room-ctnr li'); for (let ysly_room_ctnr_item of ysly_room_ctnr) { hide_Handle(ysly_room_ctnr_item, ysly_room_ctnr_item.querySelector('.uname'), ysly_room_ctnr_item.querySelector('.room-name'), 0, false, true); } let list = document.querySelectorAll('ul.list li'); for (let list_item of list) { hide_Handle(list_item, list_item.querySelector('.room-anchor > span'), list_item.querySelector('.room-title'), 0, false, true); } let card_items = document.querySelectorAll('.card-items li'); for (let card_items_ele of card_items) { hide_Handle(card_items_ele, card_items_ele.querySelector('.uname'), card_items_ele.querySelector('.room-name'), 0, false, true); } hide_Comment(); } else if (/space\.bilibili\.com\/\d+\/dynamic$/.test(OLD_URL)) { hide_Comment(); } } function hide_Comment() { let comment_list = document.querySelectorAll('.comment-list .list-item'); for (let comment_list_item of comment_list) { let comment_text = ''; if (bilibili_config.convertEmojiEnable) { comment_text = comment_list_item.querySelector('.con > p.text').innerHTML.replace(//g, "$1"); } else { comment_text = comment_list_item.querySelector('.con > p.text'); } hide_Handle(comment_list_item, comment_list_item.querySelector('.con > .user a.name'), comment_text, 0, true); } let reply_comment_list = document.querySelectorAll('.comment-list .reply-item'); for (let reply_comment_list_item of reply_comment_list) { let reply_comment_text = ''; if (bilibili_config.convertEmojiEnable) { reply_comment_text = reply_comment_list_item.querySelector('.reply-con .text-con').innerHTML.replace(//g, "$1"); } else { reply_comment_text = reply_comment_list_item.querySelector('.reply-con .text-con'); } hide_Handle(reply_comment_list_item, reply_comment_list_item.querySelector('.reply-con .user a.name'), reply_comment_text, 0, true); } } function init_Bilibili() { let style_dom = document.createElement('style'); style_dom.type = 'text/css'; style_dom.innerHTML = STYLE_VALUE; let expand_box = document.createElement('div'); expand_box.className = 'expand_box'; expand_box.onmouseenter = function() { this.classList.add('show_expand_box'); }; expand_box.onmouseleave = function() { this.classList.remove('show_expand_box'); }; let expand_span = document.createElement('span'); expand_span.id = 'expandSpan'; expand_span.title = '显示屏蔽设置'; expand_span.textContent = '屏蔽'; expand_span.addEventListener('click', function () { expand_Wrap('wrapDiv'); }, false); expand_box.appendChild(expand_span); console.info('bilibili_Block Ver.1.1.2: Console debug test. If there is no print prompt later, there is a problem with the script. Please feedback to me.'); document.arrive('body', {fireOnAttributesModification: true, onceOnly: true, existing: true}, function() { console.info('bilibili_Block Ver.1.1.2: Insert block icon. The script works fine.'); document.body.appendChild(expand_box); document.body.appendChild(style_dom); create_Settings(); }); } function create_Settings(dispaly = false) { let wrap_div = document.createElement('div'); wrap_div.id = 'wrapDiv'; if (dispaly) { wrap_div.className = 'show_wrap'; } else { wrap_div.className = 'hide_wrap'; } let main_tag = document.createElement('fieldset'); main_tag.id = 'mainTag'; wrap_div.appendChild(main_tag); let ul_tag = document.createElement('ul'); ul_tag.className = 'ul_tag'; main_tag.appendChild(ul_tag); insert_Checkbox(ul_tag, CHECKBOX_VALUE.START, bilibili_config.functionEnable, false); insert_Separator(ul_tag, '屏蔽视频:'); insert_Checkbox(ul_tag, CHECKBOX_VALUE.VIDEO_USERNAME, bilibili_config.usernameEnable, false); insert_Checkbox(ul_tag, CHECKBOX_VALUE.VIDEO_KEYWORD, bilibili_config.keywordEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.VIDEO_REG, bilibili_config.regEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.LIVE, bilibili_config.liveEnable); insert_Separator(ul_tag, '屏蔽评论:'); insert_Checkbox(ul_tag, CHECKBOX_VALUE.COMMENT_USERNAME, bilibili_config.commentEnable, false); insert_Checkbox(ul_tag, CHECKBOX_VALUE.COMMENT_KEYWORD, bilibili_config.commentKeywordEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.COMMENT_REG, bilibili_config.commentRegEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.CONVERT_EMOJI, bilibili_config.convertEmojiEnable); insert_Separator(ul_tag); insert_Separator(ul_tag, '用户名:', MODULE.USERNAME.className); insert_Input(ul_tag, INPUT_VALUE.USERNAME, TEXTAREA_VALUE.USERNAME.id, MODULE.USERNAME.className); insert_Textarea(ul_tag, TEXTAREA_VALUE.USERNAME, bilibili_config.usernameArray, MODULE.USERNAME.className); insert_Separator(ul_tag); insert_Separator(ul_tag, '视频关键字:', MODULE.VIDEO_KEYWORD.className); insert_Input(ul_tag, INPUT_VALUE.VIDEO_KEYWORD, TEXTAREA_VALUE.VIDEO_KEYWORD.id, MODULE.VIDEO_KEYWORD.className); insert_Textarea(ul_tag, TEXTAREA_VALUE.VIDEO_KEYWORD, bilibili_config.keywordArray, MODULE.VIDEO_KEYWORD.className); insert_Separator(ul_tag); insert_Separator(ul_tag, '视频正则表达式:', MODULE.VIDEO_REG.className); insert_Reg_Input(ul_tag, INPUT_VALUE.VIDEO_REG, INPUT_VALUE.VIDEO_MODIFIER, TEXTAREA_VALUE.VIDEO_REG.id, MODULE.VIDEO_REG.className); insert_Textarea(ul_tag, TEXTAREA_VALUE.VIDEO_REG, bilibili_config.regArray, MODULE.VIDEO_REG.className); insert_Separator(ul_tag); insert_Separator(ul_tag, '评论关键字:', MODULE.COMMENT_KEYWORD.className); insert_Input(ul_tag, INPUT_VALUE.COMMENT_KEYWORD, TEXTAREA_VALUE.COMMENT_KEYWORD.id, MODULE.COMMENT_KEYWORD.className); insert_Textarea(ul_tag, TEXTAREA_VALUE.COMMENT_KEYWORD, bilibili_config.commentArray, MODULE.COMMENT_KEYWORD.className); insert_Separator(ul_tag); insert_Separator(ul_tag, '评论正则表达式:', MODULE.COMMENT_REG.className); insert_Reg_Input(ul_tag, INPUT_VALUE.COMMENT_REG, INPUT_VALUE.COMMENT_MODIFIER, TEXTAREA_VALUE.COMMENT_REG.id, MODULE.COMMENT_REG.className); insert_Textarea(ul_tag, TEXTAREA_VALUE.COMMENT_REG, bilibili_config.commentRegArray, MODULE.COMMENT_REG.className); insert_Separator(ul_tag); let save_button = create_Span_Btn(BUTTON_VALUE.SAVE, function() { save_Config(); }); let only_save_button = create_Span_Btn(BUTTON_VALUE.ONLY_SAVE, function() { save_Config(false); }); let cancel_button = create_Span_Btn(BUTTON_VALUE.CANCEL, function(e) { expand_Wrap('wrapDiv'); setTimeout(function() { document.body.removeChild(wrap_div); create_Settings(); }, 800); e.stopPropagation(); }); ul_tag.appendChild(save_button); ul_tag.appendChild(only_save_button); ul_tag.appendChild(cancel_button); document.body.appendChild(wrap_div); } function save_Config(close_status = true) { bilibili_config.functionEnable = document.getElementById(CHECKBOX_VALUE.START.id).checked; bilibili_config.usernameEnable = document.getElementById(CHECKBOX_VALUE.VIDEO_USERNAME.id).checked; bilibili_config.keywordEnable = document.getElementById(CHECKBOX_VALUE.VIDEO_KEYWORD.id).checked; bilibili_config.commentEnable = document.getElementById(CHECKBOX_VALUE.COMMENT_USERNAME.id).checked; bilibili_config.commentKeywordEnable = document.getElementById(CHECKBOX_VALUE.COMMENT_KEYWORD.id).checked; bilibili_config.regEnable = document.getElementById(CHECKBOX_VALUE.VIDEO_REG.id).checked; bilibili_config.commentRegEnable = document.getElementById(CHECKBOX_VALUE.COMMENT_REG.id).checked; bilibili_config.convertEmojiEnable = document.getElementById(CHECKBOX_VALUE.CONVERT_EMOJI.id).checked; bilibili_config.liveEnable = document.getElementById(CHECKBOX_VALUE.LIVE.id).checked; bilibili_config.usernameArray = extract_Array(TEXTAREA_VALUE.USERNAME.id); bilibili_config.keywordArray = extract_Array(TEXTAREA_VALUE.VIDEO_KEYWORD.id); bilibili_config.commentArray = extract_Array(TEXTAREA_VALUE.COMMENT_KEYWORD.id); bilibili_config.regArray = extract_Array(TEXTAREA_VALUE.VIDEO_REG.id); bilibili_config.commentRegArray = extract_Array(TEXTAREA_VALUE.COMMENT_REG.id); reg_config.regArray = convert_Array(bilibili_config.regArray); reg_config.commentRegArray = convert_Array(bilibili_config.commentRegArray); GM_setValue('bilibili_config', bilibili_config); hide_Event(); if (close_status) { expand_Wrap('wrapDiv'); } } Promise.all([GM_getValue('bilibili_config')]).then(function (data) { if (data[0] !== undefined) { bilibili_config = data[0]; } if (bilibili_config.commentArray === undefined) { bilibili_config.commentArray = []; } if (bilibili_config.regArray === undefined) { bilibili_config.regArray = []; } if (bilibili_config.commentRegArray === undefined) { bilibili_config.commentRegArray = []; } if (bilibili_config.regArray.length > 0) { reg_config.regArray = convert_Array(bilibili_config.regArray); } if (bilibili_config.commentRegArray.length > 0) { reg_config.commentRegArray = convert_Array(bilibili_config.commentRegArray); } init_Bilibili(); hide_Event(); try { GM_addValueChangeListener('bilibili_config', function(name, old_value, new_value, remote) { if (remote) { bilibili_config = new_value; let wrap_div = document.getElementById('wrapDiv'); if (wrap_div.classList.contains('show_wrap')) { document.body.removeChild(wrap_div); create_Settings(true); hide_Event(); } else { document.body.removeChild(wrap_div); create_Settings(); hide_Event(); } } }); } catch (e) { console.error(e); } try { GM_registerMenuCommand('bilibili_屏蔽设置', function () { expand_Wrap('wrapDiv'); }); } catch (e) { console.error(e); } document.arrive('body', {fireOnAttributesModification: true, onceOnly: true, existing: true}, function() { try { let observer = new MutationObserver(function () { hide_Event(); }); let listener_container = document.querySelector("body"); let option = { 'childList': true, 'subtree': true }; observer.observe(listener_container, option); } catch (e) { console.error(e); } if (/www\.bilibili\.com\/?(\/\?spm_id_from=.*)?$/.test(OLD_URL)) { if (document.querySelector('.btn.next')) { document.querySelector('.btn.next').addEventListener('click', function() { setTimeout(function() { hide_Event(); }, 250); }); } if (document.querySelector('.btn.prev')) { document.querySelector('.btn.prev').addEventListener('click', function() { setTimeout(function() { hide_Event(); }, 250); }); } document.body.arrive('.manga-panel .btn-change', {fireOnAttributesModification: true, onceOnly: true, existing: true}, function() { this.addEventListener('click', function() { setTimeout(function() { hide_Event(); }, 1000); }); }); document.body.arrive('.manga-panel .tab-switch-item', {fireOnAttributesModification: true, onceOnly: true, existing: true}, function() { this.addEventListener('click', function() { setTimeout(function() { hide_Event(); }, 1000); }); }); } if (/live\.bilibili\.com\/all/.test(OLD_URL)) { document.body.arrive('.content-panel h1.title > span', {fireOnAttributesModification: true, onceOnly: true, existing: true}, function() { this.addEventListener('click', function() { setTimeout(function() { hide_Event(); }, 1000); }); }); } }); }).catch(function (except) { console.error(except); }); })();