// ==UserScript== // @name 哔哩哔哩 - 屏蔽指定内容 // @namespace https://greasyfork.org/zh-CN/users/193133-pana // @homepage https://www.sailboatweb.com // @version 3.5.3 // @description 实现可分别按用户名、关键字、正则表达式对视频或评论进行屏蔽; 鼠标移至网页右下角弹出悬浮按钮 // @author pana // @include http*://www.bilibili.com/* // @include http*://search.bilibili.com/* // @require https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js // @grant GM_getValue // @grant GM_setValue // @grant GM_setClipboard // @grant GM_registerMenuCommand // @run-at document-start // @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_ARRAY: ['startCheckbox', '启用屏蔽功能', '总开关'], USERNAME_ARRAY: ['usernameCheckbox', '按用户名', '屏蔽指定用户发布的视频'], KEYWORD_ARRAY: ['keywordCheckbox', '按关键字', '屏蔽标题中包含指定关键字的视频'], REG_ARRAY: ['regCheckbox', '按正则表达式', '屏蔽标题匹配指定正则表达式的视频'], COMMENT_USERNAME_ARRAY: ['commentUsernameCheckbox', '按用户名', '屏蔽指定用户发布的评论'], COMMENT_KEYWORD_ARRAY: ['commentKeywordCheckbox', '按关键字', '屏蔽内容中包含指定关键字的评论'], COMMENT_REG_ARRAY: ['commentRegCheckbox', '按正则表达式', '屏蔽内容匹配指定正则表达式的评论'], CONVERT_EMOJI_ARRAY: ['convertEmojiCheckbox', '将表情转换成文字', '判定时将表情包转换成对应的标识文字,例:[doge]'] }; const INPUT_VALUE = { ADD_USERNAME_ARRAY: ['addUsernameInput', '输入:', '(多个时以半角逗号分隔)'], ADD_VIDEO_TITLE_ARRAY: ['addVideoTitleInput', '输入:', '(多个时以半角逗号分隔)'], ADD_COMMENT_ARRAY: ['addCommentInput', '输入:', '(多个时以半角逗号分隔)'], ADD_VIDEO_TITLE_REG_ARRAY: ['addVideoTitleRegInput', '输入:', '( / 建议写成 \\/ )'], ADD_VIDEO_TITLE_MODIFIER_ARRAY: ['addVideoTitleModifierInput', '修饰符:', '(如:gim)'], ADD_COMMENT_REG_ARRAY: ['addCommentRegInput', '输入:', '( / 建议写成 \\/ )'], ADD_COMMENT_MODIFIER_ARRAY: ['addCommentModifierInput', '修饰符:', '(如:gim)'] }; const TEXTAREA_VALUE = { USERNAME_ARRAY: ['usernameTextarea', ''], VIDEO_TITLE_KEYWORD_ARRAY: ['videoTitleKeywordTextarea', ''], COMMENT_KEYWORD_ARRAY: ['commentKeywordTextarea', ''], VIDEO_TITLE_REG_ARRAY: ['videoTitleRegTextarea', ''], COMMENT_REG_ARRAY: ['commentRegTextarea', ''] }; 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; } #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: 452px; z-index: 99999; } .show_wrap { display: block; right: 0; } .hide_wrap { right: -460px; } #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; height: 15px; margin-left: 5px; margin-right: 5px; padding-left: 4px; } .input_btn { background-color: #73C9E5; border-radius: 4px; border: 1px solid #73C9E5; box-shadow: 0 0 4px #73C9E5; color: #FFF; cursor: pointer; display: inline-block; height: 15px; line-height: 15px; margin-left: 5px; text-align: center; vertical-align: bottom; width: 28px; } .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: #555; border-radius: 5px; width: 10px; } .textarea_list_div::-webkit-scrollbar-thumb { background-color: #333; border-radius: 5px; } .textarea_copied { color: cyan; } .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; } .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; } #saveButton, #onlySaveButton { float: right; margin-right: 5px; } #cancelButton { float: left; margin-left: 5px; } `; var bilibili_config = { functionEnable: true, usernameEnable: true, keywordEnable: true, commentEnable: false, commentKeywordEnable: false, regEnable: false, commentRegEnable: false, convertEmojiEnable: 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 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.log('bilibili_BLock Ver.2.1.2: The transformation contains invalid regular expressions.'); console.log(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].innerText) } } return re_arr } 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 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.log('bilibili_Block Ver.2.1.0: Invalid regular expression.'); console.log(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' } else { document.getElementById(id_value).className = 'show_wrap' } } else { create_Settings() } } function insert_Separator(ul_node, text_value = '') { let temp_li = document.createElement('li'); let temp_div = document.createElement('div'); if (text_value) { temp_div.className = 'separator_text'; temp_div.innerText = text_value } else { temp_div.className = 'separator_symbol' } temp_li.appendChild(temp_div); ul_node.appendChild(temp_li) } function insert_Checkbox(ul_node, li_array, 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_array[0]; 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_array[0]); temp_label.innerText = li_array[1]; temp_label.title = li_array[2]; temp_li.appendChild(temp_input); temp_li.appendChild(temp_label); ul_node.appendChild(temp_li) } function insert_Input(ul_node, li_array, list_id) { let temp_li = document.createElement('li'); let temp_div = document.createElement('div'); temp_div.className = 'input_div'; temp_div.innerText = li_array[1]; let temp_input = document.createElement('input'); temp_input.id = li_array[0]; temp_input.placeholder = li_array[2]; 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 = document.createElement('span'); add_btn.innerText = '添加'; add_btn.title = '添加内容到列表中'; add_btn.className = 'input_btn'; add_btn.addEventListener('click', function() { add_Child(temp_input, list_id) }); let clear_btn = document.createElement('span'); clear_btn.innerText = '清空'; clear_btn.title = '清空列表'; clear_btn.className = 'input_btn'; clear_btn.addEventListener('click', function() { document.getElementById(list_id).innerHTML = '' }); let copy_btn = document.createElement('span'); copy_btn.innerText = '复制'; copy_btn.title = '复制列表'; copy_btn.className = 'input_btn'; copy_btn.addEventListener('click', function() { GM_setClipboard(array_2_String(extract_Array(list_id))); this.classList.add('textarea_copied'); this.title = '复制完成' }); temp_div.appendChild(temp_input); temp_div.appendChild(add_btn); temp_div.appendChild(clear_btn); temp_div.appendChild(copy_btn); temp_li.appendChild(temp_div); ul_node.appendChild(temp_li) } function insert_Reg_Input(ul_node, reg_array, modifier_array, list_id) { let temp_li = document.createElement('li'); let temp_div = document.createElement('div'); temp_div.className = 'input_div'; let reg_span = document.createElement('span'); reg_span.innerText = reg_array[1]; let reg_input = document.createElement('input'); reg_input.id = reg_array[0]; reg_input.placeholder = reg_array[2]; reg_input.type = 'text'; reg_input.className = 'user_block_input reg_input'; let modifier_span = document.createElement('span'); modifier_span.innerText = modifier_array[1]; let modifier_input = document.createElement('input'); modifier_input.id = modifier_array[0]; modifier_input.placeholder = modifier_array[2]; modifier_input.type = 'text'; modifier_input.className = 'user_block_input modifier_input'; let add_btn = document.createElement('span'); add_btn.innerText = '添加'; add_btn.title = '添加正则表达式'; add_btn.className = 'input_btn'; add_btn.addEventListener('click', function() { add_Reg_Child(reg_input, modifier_input, list_id) }); let clear_btn = document.createElement('span'); clear_btn.innerText = '清空'; clear_btn.title = '清空列表'; clear_btn.className = 'input_btn'; clear_btn.addEventListener('click', function() { document.getElementById(list_id).innerHTML = '' }); let copy_btn = document.createElement('span'); copy_btn.innerText = '复制'; copy_btn.title = '复制列表'; copy_btn.className = 'input_btn'; copy_btn.addEventListener('click', function() { GM_setClipboard(array_2_String(extract_Array(list_id))); this.classList.add('textarea_copied'); this.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(clear_btn); temp_div.appendChild(copy_btn); temp_li.appendChild(temp_div); ul_node.appendChild(temp_li) } function insert_Textarea(ul_node, li_array, save_array) { let temp_li = document.createElement('li'); 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_array[0]; 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_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.innerText = (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.innerText = '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 decide_Text(text_value, is_comment = 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.log('bilibili_BLock Ver.2.1.0: Invalid regular expression for comparison.'); console.log(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.log('bilibili_BLock Ver.2.1.0: Invalid regular expression for comparison.'); console.log(e); return false } } } } return false } function decide_Username(username, is_comment = false) { if (bilibili_config.functionEnable && username) { if (is_comment) { if (bilibili_config.commentEnable) { 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_Handle(item_node, username, text_value, method = 0, is_comment = false) { if (username) { if (typeof(username) === 'object') { username = username.textContent } } if (text_value) { if (typeof(text_value) === 'object') { text_value = text_value.textContent } } if (decide_Username(username, is_comment)) { if (method === 0) { item_node.style.display = 'none' } else if (method === 1) { item_node.style.visibility = 'hidden' } } else if (decide_Text(text_value, is_comment)) { if (method === 0) { item_node.style.display = 'none' } else if (method === 1) { item_node.style.visibility = 'hidden' } } else { if (method === 0) { item_node.style.display = '' } else if (method === 1) { item_node.style.visibility = '' } } } 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 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')) } 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')) } 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 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) { 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) } } 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')) } } } 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.innerText = '屏蔽'; expand_span.addEventListener('click', function() { expand_Wrap('wrapDiv') }, false); expand_box.appendChild(expand_span); console.log('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.log('bilibili_Block Ver.1.1.2: Insert block icon. The script works fine.'); document.body.appendChild(expand_box); document.body.appendChild(style_dom) }) } function create_Settings() { let wrap_div = document.createElement('div'); wrap_div.id = 'wrapDiv'; wrap_div.className = 'show_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_ARRAY, bilibili_config.functionEnable, false); insert_Separator(ul_tag, '屏蔽视频:'); insert_Checkbox(ul_tag, CHECKBOX_VALUE.USERNAME_ARRAY, bilibili_config.usernameEnable, false); insert_Checkbox(ul_tag, CHECKBOX_VALUE.KEYWORD_ARRAY, bilibili_config.keywordEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.REG_ARRAY, bilibili_config.regEnable); insert_Separator(ul_tag, '屏蔽评论:'); insert_Checkbox(ul_tag, CHECKBOX_VALUE.COMMENT_USERNAME_ARRAY, bilibili_config.commentEnable, false); insert_Checkbox(ul_tag, CHECKBOX_VALUE.COMMENT_KEYWORD_ARRAY, bilibili_config.commentKeywordEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.COMMENT_REG_ARRAY, bilibili_config.commentRegEnable); insert_Checkbox(ul_tag, CHECKBOX_VALUE.CONVERT_EMOJI_ARRAY, bilibili_config.convertEmojiEnable); insert_Separator(ul_tag); insert_Separator(ul_tag, '用户名:'); insert_Input(ul_tag, INPUT_VALUE.ADD_USERNAME_ARRAY, TEXTAREA_VALUE.USERNAME_ARRAY[0]); insert_Textarea(ul_tag, TEXTAREA_VALUE.USERNAME_ARRAY, bilibili_config.usernameArray); insert_Separator(ul_tag); insert_Separator(ul_tag, '视频标题关键字:'); insert_Input(ul_tag, INPUT_VALUE.ADD_VIDEO_TITLE_ARRAY, TEXTAREA_VALUE.VIDEO_TITLE_KEYWORD_ARRAY[0]); insert_Textarea(ul_tag, TEXTAREA_VALUE.VIDEO_TITLE_KEYWORD_ARRAY, bilibili_config.keywordArray); insert_Separator(ul_tag); insert_Separator(ul_tag, '视频标题正则表达式:'); insert_Reg_Input(ul_tag, INPUT_VALUE.ADD_VIDEO_TITLE_REG_ARRAY, INPUT_VALUE.ADD_VIDEO_TITLE_MODIFIER_ARRAY, TEXTAREA_VALUE.VIDEO_TITLE_REG_ARRAY[0]); insert_Textarea(ul_tag, TEXTAREA_VALUE.VIDEO_TITLE_REG_ARRAY, bilibili_config.regArray); insert_Separator(ul_tag); insert_Separator(ul_tag, '评论关键字:'); insert_Input(ul_tag, INPUT_VALUE.ADD_COMMENT_ARRAY, TEXTAREA_VALUE.COMMENT_KEYWORD_ARRAY[0]); insert_Textarea(ul_tag, TEXTAREA_VALUE.COMMENT_KEYWORD_ARRAY, bilibili_config.commentArray); insert_Separator(ul_tag); insert_Separator(ul_tag, '评论正则表达式:'); insert_Reg_Input(ul_tag, INPUT_VALUE.ADD_COMMENT_REG_ARRAY, INPUT_VALUE.ADD_COMMENT_MODIFIER_ARRAY, TEXTAREA_VALUE.COMMENT_REG_ARRAY[0]); insert_Textarea(ul_tag, TEXTAREA_VALUE.COMMENT_REG_ARRAY, bilibili_config.commentRegArray); insert_Separator(ul_tag); let save_button = document.createElement('button'); save_button.id = 'saveButton'; save_button.className = 'user_block_button'; save_button.type = 'button'; save_button.innerText = '保存并关闭'; save_button.title = '保存设置并关闭设置窗口'; ul_tag.appendChild(save_button); let only_save_button = document.createElement('button'); only_save_button.id = 'onlySaveButton'; only_save_button.className = 'user_block_button'; only_save_button.type = 'button'; only_save_button.innerText = '仅保存'; only_save_button.title = '仅保存设置'; ul_tag.appendChild(only_save_button); let cancel_button = document.createElement('button'); cancel_button.id = 'cancelButton'; cancel_button.className = 'user_block_button'; cancel_button.type = 'button'; cancel_button.innerText = '取消'; cancel_button.title = '关闭设置窗口'; ul_tag.appendChild(cancel_button); save_button.addEventListener('click', function() { save_Config() }, false); only_save_button.addEventListener('click', function() { save_Config(false) }, false); cancel_button.addEventListener('click', function(e) { expand_Wrap('wrapDiv'); e.stopPropagation() }, false); document.body.appendChild(wrap_div) } function save_Config(close_status = true) { bilibili_config.functionEnable = document.getElementById(CHECKBOX_VALUE.START_ARRAY[0]).checked; bilibili_config.usernameEnable = document.getElementById(CHECKBOX_VALUE.USERNAME_ARRAY[0]).checked; bilibili_config.keywordEnable = document.getElementById(CHECKBOX_VALUE.KEYWORD_ARRAY[0]).checked; bilibili_config.commentEnable = document.getElementById(CHECKBOX_VALUE.COMMENT_USERNAME_ARRAY[0]).checked; bilibili_config.commentKeywordEnable = document.getElementById(CHECKBOX_VALUE.COMMENT_KEYWORD_ARRAY[0]).checked; bilibili_config.regEnable = document.getElementById(CHECKBOX_VALUE.REG_ARRAY[0]).checked; bilibili_config.commentRegEnable = document.getElementById(CHECKBOX_VALUE.COMMENT_REG_ARRAY[0]).checked; bilibili_config.convertEmojiEnable = document.getElementById(CHECKBOX_VALUE.CONVERT_EMOJI_ARRAY[0]).checked; bilibili_config.usernameArray = extract_Array(TEXTAREA_VALUE.USERNAME_ARRAY[0]); bilibili_config.keywordArray = extract_Array(TEXTAREA_VALUE.VIDEO_TITLE_KEYWORD_ARRAY[0]); bilibili_config.commentArray = extract_Array(TEXTAREA_VALUE.COMMENT_KEYWORD_ARRAY[0]); bilibili_config.regArray = extract_Array(TEXTAREA_VALUE.VIDEO_TITLE_REG_ARRAY[0]); bilibili_config.commentRegArray = extract_Array(TEXTAREA_VALUE.COMMENT_REG_ARRAY[0]); 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_registerMenuCommand('bilibili_屏蔽设置', function() { expand_Wrap('wrapDiv') }) } catch (e) { console.log(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.log(e) } if (/bilibili\.com\/?(\/\?spm_id_from=.*)?$/.test(OLD_URL)) { document.querySelector('.btn.next').addEventListener('click', function() { setTimeout(function() { hide_Event() }, 250) }); document.querySelector('.btn.prev').addEventListener('click', function() { setTimeout(function() { hide_Event() }, 250) }) } }) }). catch (function(except) { console.log(except) }) })();