// ==UserScript== // @name BiliBili Tags Blocker BiliBili标签屏蔽助手 // @namespace https://greasyfork.org/zh-CN/users/924205-xiao-xi // @version 0.10.5 // @description 眼不见为净,耳不听为清,心不想则静 // @author xiaoxi // @license MIT // @include *://www.bilibili.com/* // @include *://t.bilibili.com/* // @include *://search.bilibili.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com // @require https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js // @require https://unpkg.com/ajax-hook@2.1.3/dist/ajaxhook.min.js // @require https://cdn.jsdelivr.net/npm/arrive@2.4.1/minified/arrive.min.js // @require https://greasyfork.org/scripts/407543-block-obj/code/Block_Obj.js?version=963893 // @grant GM_xmlhttpRequest // @grant unsafeWindow // @grant GM_getValue // @grant GM.getValue // @grant GM_setValue // @grant GM.setValue // @grant GM_setClipboard // @grant GM.setClipboard // @grant GM_registerMenuCommand // @grant GM_addValueChangeListener // @run-at document-start // @downloadURL none // ==/UserScript== var tagsBlocker = { functionEnable: true, onlyChangeColorEnable: false, printLog: false, blurMode: false, hiddenMode: false, tagsArray: [], titlesArray: [], }; var href = location.href; var matchSearch = href.match(/search.bilibili/); var matchPopular = href.match(/popular/); var matchRank = href.match(/\/popular\/rank/); var matchPost = href.match(/t.bilibili/); var matchVideo = href.match(/video/); var matchHome = href.match(/bilibili.com/); var blockObj = new Block_Obj('Tags_Blocker'); const BASIC_STYLE = ` .block_obj_checkbox_label { padding-left: 13px; } `; const tagsApi = 'https://api.bilibili.com/x/web-interface/view/detail/tag?bvid='; //加载选项 document.arrive("body", { fireOnAttributesModification: true, onceOnly: true, existing: true }, function() { initSettingUI() }); function initSettingUI(){ blockObj.init({ id: 'tagsBlocker', menu: '屏蔽设置', style: BASIC_STYLE, field: [ { id: 'version', label: 'v0.10.5', type: 's', }, { id: 'functionEnable', label: '启用屏蔽功能', title: '总开关', type: 'c', default: true, }, { id: 'onlyChangeColorEnable', label: '看看屏蔽了什么', title: '更改屏蔽视频的背景色', type: 'c', default: false, }, { id: 'printLog', label: '在控制台输出匹配的视频信息', title: '。。', type: 'c', default: false, }, { label: '屏蔽模式', type: 's', }, { id: 'blurMode', label: '模糊模式', type: 'c', default: false, }, { id: 'hiddenMode', label: '隐藏模式', type: 'c', default: false, }, { label: '标签关键字', type: 's', }, { id: 'tagInput', label: '', placeholder: ' 同时输入多个时以英文逗号分隔 ', type: 'i', list_id: 'tagsArray', }, { id: 'tagsArray', type: 'l', default: [], }, { label: '标题关键字 (例如‘原 神’标题,请输入‘原神’)', type: 's', }, { id: 'titleInput', label: '', placeholder: ' 同时输入多个时以英文逗号分隔 ', type: 'i', list_id: 'titlesArray', }, { id: 'titlesArray', type: 'l', default: [], }, ], events: { save: config => { tagsBlocker = config; }, change: config => { tagsBlocker = config; }, }, }) } class VideoCard{ constructor(card,title,bv) { this.card = card; this.title = replaceAllSymbol(title); this.bv = bv; this.tags = null; this.typeName = null; this.match = null; this.where = null; } } class Listener{ constructor(targetNode, nth, options = {}) { this.targetNode = targetNode; this.nth = nth; this.options = options; } init(initMethod,callMethod){ let targetNode = $(this.targetNode)[this.nth]; let options = this.options; function callback(mutationsList, observer) { if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length != 0){ callFunc(callMethod,mutationsList) } } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null && targetNode.length != 0){ mutationObserver.observe(targetNode, options); callFunc(initMethod,targetNode) clearInterval(checkTarget); } else { targetNode = $(this.targetNode)[this.nth]; } }, 50); } } class Match{ init(url,parameter,callMethod){ return new Promise(function(resolve) { $.ajax(url + parameter.bv, { method: 'GET', headers: { "content-type": "application/json" }, async: true, success: function (result) { parameter.tags = result.data resolve(callFunc(callMethod,parameter)); }, error: function (result) { console.log(result) }, }); }); } } var match = new Match(); //==视频页==// function videoInit(card){ let info = $(card).children(".card-box").children(".info").children("a") let href = $(info).attr("href"); let title = $(info).children('span').attr("title"); let videoCard = $(card); let bv = getBvcountber(href); let v1 = new VideoCard(videoCard,title,bv); return v1 } function videoListenerInit(targetNode){ $.each($(targetNode).children(".video-page-card"), function(i, card){ let v1 = videoInit(card) match.init(tagsApi,v1,finalMatch) }); } function videoListenerCall(targetNode){ $.each(targetNode, function(i, m){ let v1 = videoInit(m.addedNodes[0]) match.init(tagsApi,v1,finalMatch) }); } function ad1(){ //.video-page-special-card //#live_recommand_report //#activity_vote document.arrive(".video-page-special-card", { fireOnAttributesModification: true, onceOnly: true, existing: true }, function() { $(this).css({"display":"none"}); }); document.arrive("#live_recommand_report", { fireOnAttributesModification: true, onceOnly: true, existing: true }, function() { $(this).css({"display":"none"}); }); document.arrive("#activity_vote", { fireOnAttributesModification: true, onceOnly: true, existing: true }, function() { $(this).css({"display":"none"}); }); //结束视频 $(document).arrive('.bpx-player-ending-related', {fireOnAttributesModification: true, onceOnly: true, existing: true},function(){ $(this).remove(); $('.bpx-player-ending-functions').animate({ marginTop: 145, opacity: 'show' }, "slow"); }) $(document).arrive('.bpx-player-popup', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).remove(); }) $(document).arrive('.bpx-player-follow', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).remove(); }) //三连 $(document).arrive('.bpx-player-popup-guide-all', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).remove(); }) //投票 $(document).arrive('.bpx-player-popup-vote', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).remove(); }) //跳转其他视频 $(document).arrive('.bpx-player-link', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).remove(); }) //评分 $(document).arrive('.bpx-player-score', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).remove(); }) //推广视频 $(document).arrive('.video-ad-creative-card', {fireOnAttributesModification: true, onceOnly: true, existing: true},function(){ $(this).css({"display":"none"}) }) //右下角推广 $(document).arrive('#right-bottom-banner', {fireOnAttributesModification: true, onceOnly: true, existing: true},function(){ $(this).css({"display":"none"}) }) } $(document).arrive('.reply-notice', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).css({"display":"none"}) }) $(document).arrive('.trending', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ $(this).css({"display":"none"}) }) //==动态导航栏==// function barListenerInit(targetNode){ let navbarListener = new Listener('.video-list', 0, {childList: true}) navbarListener.init(navbarListenerInit,navbarListenerCall) } function barListenerCall(targetNode){ targetNode.map(r => { if(r.addedNodes[0] != null){ let tab = $(r.addedNodes[0]) if(tab.hasClass('video-tab')){ let navbarListener = new Listener('.video-list', 0, {childList: true}) navbarListener.init(navbarListenerInit,navbarListenerCall) } } }) } function navbarInit(card){ let href = $(card).children(".main-container").children("a").attr("href"); let title = $(card).children(".main-container").children(".center-box").children("a").attr('title') let videoCard = $(card); let bv = getBvcountber(href) let v1 = new VideoCard(videoCard,title,bv); return v1 } function navbarListenerInit(targetNode){ let checkTarget = setInterval(function () { if($(targetNode).children(".list-item").length > 1){ clearInterval(checkTarget); $.each($(targetNode).children(".list-item"), function(i, card){ let v1 = navbarInit(card) match.init(tagsApi,v1,finalMatch) }); } }, 50); } function navbarListenerCall(targetNode){ $.each(targetNode, function(i, m){ let v1 = navbarInit(m.addedNodes[0]) match.init(tagsApi,v1,finalMatch) }); } //==热门页面==// function initPopularVideoInfo(url){ let l1 = url.indexOf('pn='); let num = url.substring(l1+3,url.length) let checkTarget = setInterval(function () { let videoCardList = $(".video-card__content"); if(videoCardList != null && videoCardList != undefined){ clearInterval(checkTarget); if(num != 1){ if(tagsBlocker.blurMode){ videoCardList = videoCardList.slice((num-1)*20,videoCardList.length) } } videoCardList.each(function(i){ let href = $(this).children("a").attr("href"); let videoCard = $(this).parent(".video-card"); let title = $($(videoCard).children(".video-card__info")).children("p").attr("title"); let v1 = new VideoCard(videoCard,title,"BV"+getBvcountber(href)); v1.where = 'popular' match.init(tagsApi,v1,finalMatch) }); } }, 50); } //==排行榜==// function initRankVideoInfo(){ let videoCardList = $(".rank-item"); if(!location.href.match(/\/rank\/bangumi/) || !location.href.match(/\/rank\/guochan/) || !location.href.match(/\/rank\/documentary/) || !location.href.match(/\/rank\/movie/) || !location.href.match(/\/rank\/tv/) || !location.href.match(/\/rank\/variety/)){ let checkTarget = setInterval(function () { if(videoCardList != null && videoCardList != undefined && videoCardList.length != 0){ clearInterval(checkTarget); videoCardList.each(function(i){ let info = $(this).children(".content").children(".info").children("a"); let href = $(info).attr("href"); let title = $(info).text(); let videoCard = $(this); let v1 = new VideoCard(videoCard,title,"BV"+getBvcountber(href)); match.init(tagsApi,v1,finalMatch) }); } else{ videoCardList = $(".rank-item"); } }, 50); } } //==搜索页==// function initSearchVideoInfo(responses){ let checkTarget = setInterval(function () { if(responses.length >= 1){ let r = [] let checkTarget1 = setInterval(function () { if(r.length > 1 ){ setVideoInfo(r[0]) clearInterval(checkTarget1); } else { $.each(responses,function(i,t){ if(t.result_type == 'video'){ r.push(t) } }) } }, 50); clearInterval(checkTarget); } }, 50); } function setVideoInfo(tagList){ let videoList = $('.video-list.clearfix').children('.video-item.matrix') videoList.each(function(i,v){ let tags = tagList.data[i].tag.split(','); let typeName = tagList.data[i].typename; let title = $($($(v).children('.info')).children('.headline')).children('a').attr('title') let v1 = new VideoCard($(v),title,-1); let newTags = []; tags.map(function(item) { let t = {tag_name : item} newTags.push(t) }); v1.tags = newTags; v1.typeName = typeName; finalMatch(v1) }) } function reSetOption(){ $(document).arrive('.filter-type.clearfix.order', {fireOnAttributesModification: true, onceOnly: false, existing: true},function(){ let op1 = '