// ==UserScript== // @name BiliBili Tags Blocker BiliBili标签屏蔽助手 // @namespace https://greasyfork.org/zh-CN/users/924205-xiao-xi // @version 0.4.9 // @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://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== // https://greasyfork.org/zh-CN/scripts/417760-checkjquery var BiliBiliTagsBlocker = { functionEnable: true, onlyChangeColorEnable: false, removeSpecialEnable: false, removeNextVideo: false, homeCover: false, removeRightBanner: false, removeLive: false, removeBottomActivity: false, tagsArray: [], }; const BASIC_STYLE = ` .block_obj_checkbox_label { padding-left: 13px; } `; let blockObj = new Block_Obj('BiliBili_Tags_Blocker'); function initSettingUI(){ if(!isCheckSetting){ blockObj.init({ id: 'BiliBiliTagsBlocker', menu: 'Tags屏蔽设置', style: BASIC_STYLE, field: [ { id: 'version', label: 'v0.4.9', type: 's', }, { id: 'functionEnable', label: '启用屏蔽功能', title: '总开关', type: 'c', default: true, }, { id: 'onlyChangeColorEnable', label: '看看屏蔽了什么', title: '更改屏蔽视频的背景色', type: 'c', default: false, }, { label: '首页设置', type: 's', }, { id: 'homeCover', label: '首页遮罩', title: '加载图', type: 'c', default: false, }, { label: '视频页设置', type: 's', }, { id: 'removeSpecialEnable', label: '移除特别推荐', title: '多为推广', type: 'c', default: false, }, { id: 'removeNextVideo', label: '移除接下来播放', title: '推荐的什么jb', type: 'c', default: false, }, { id: 'removeRightBanner', label: '移除右下角推广', title: '推荐的什么jb', type: 'c', default: false, }, { id: 'removeLive', label: '移除直播推荐', title: '推荐的什么jb', type: 'c', default: false, }, { id: 'removeBottomActivity', label: '移除视频下方活动', title: '什么jb玩意', type: 'c', default: false, }, { label: 'Tag设置', type: 's', }, { id: 'tagInput', label: '输入:', placeholder: ' 同时输入多个时以英文逗号分隔 ', type: 'i', list_id: 'tagsArray', //classname: MODULE.WHITELIST.className, }, { id: 'tagsArray', type: 'l', default: [], //classname: MODULE.WHITELIST.className, }, ], events: { save: config => { BiliBiliTagsBlocker = config; }, change: config => { BiliBiliTagsBlocker = config; }, }, }); } isCheckSetting = true; } var scrollTop = 0; //视频信息 var videoInfo = []; var oldVideoInfo = []; var isLoading = false; let href = location.href; let matchSearch = href.match(/search.bilibili/); let matchPopular = href.match(/popular/); let matchPost = href.match(/t.bilibili/); let matchVideo = href.match(/video/); let matchHome = href.match(/bilibili.com/); //=======================通用========================= //当前搜索区域id var currentSectionId; //获取视频信息 function initvideoInfo(match,parameter) { let loaded = 0; if(match == "popular"){ let videoCardList = $(".video-card__content"); videoCardList.each(function(i){ let href = $(this).children("a").attr("href"); let videoCard = $(this).parent(".video-card"); let videoCardTitle = videoCard.children(".video-card__info").children("p").attr("title") let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); }); } if(match == "popular-reload"){ //console.log(parameter); $.each(parameter, function(i, videoCard){ let href = videoCard.children(".video-card__content").children("a").attr("href"); let videoCardTitle = videoCard.children(".video-card__info").children("p").attr("title") let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); }); } if(match == "search"){ //let videoCardList = $("li.video-item"); let videoCardList = $(".video-item"); videoCardList.each(function(i){ let href = $(this).children("a").attr("href"); let title; if($(this).children("a").attr("title") != undefined) { title = $(this).children("a").attr("title"); } else{ var t = $(this).children("a").context.innerText.split("\n"); title = t[1]; } let bvInfo = { bv : getBvcountber(href), index : i, title : title, context : $(this) } loaded++; videoInfo.push(bvInfo); }); } if(match == "search-reload"){ parameter.each(function(i){ let href = $(this).children("a").attr("href"); let title; if($(this).children("a").attr("title") != undefined) { title = $(this).children("a").attr("title"); } else{ var t = $(this).children("a").context.innerText.split("\n"); title = t[1]; } let bvInfo = { bv : getBvcountber(href), index : i, title : title, context : $(this) } loaded++; videoInfo.push(bvInfo); }); } if(match == "post"){ let postCardList = $(".bili-dyn-list__items").children(".bili-dyn-list__item"); $(postCardList).each(function(i){ let bv = getBvcountber($(this).children(".bili-dyn-item").children(".bili-dyn-item__main").children(".bili-dyn-item__body").children(".bili-dyn-content").children(".bili-dyn-content__orig").children(".bili-dyn-content__orig__major").children("a").attr("href")); let videoCard = $(this).children(".bili-dyn-item").children(".bili-dyn-item__main"); if(bv != undefined){ let bvInfo = { bv : bv, index : i, card : $(this), color : videoCard, title : "", } loaded++; videoInfo.push(bvInfo); } }); } if(match == "post-reload"){ $(parameter).each(function(i){ let bv = getBvcountber($(this).children(".bili-dyn-item").children(".bili-dyn-item__main").children(".bili-dyn-item__body").children(".bili-dyn-content").children(".bili-dyn-content__orig").children(".bili-dyn-content__orig__major").children("a").attr("href")); let videoCard = $(this).children(".bili-dyn-item").children(".bili-dyn-item__main"); if(bv != undefined){ let bvInfo = { bv : bv, index : i, card : $(this), color : videoCard, title : "", } loaded++; videoInfo.push(bvInfo); } }); } if(match == "home"){ let videoCardList = $('.rcmd-box').children(); videoCardList.each(function(i){ if(i <= 9){ let href = $(this).children(".info-box").children("a").attr("href"); let videoCard = $(this); let videoCardTitle = $(this).children(".info-box").children("a").children("img").attr("alt") let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); } }); } if(match == "navbar"){ let videoCardList = $(parameter).children(".list-item"); videoCardList.each(function(i){ let href = $(this).children(".main-container").children("a").attr("href"); let videoCard = $(this); let videoCardTitle = $(this).attr("title") let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); }); } if(match == "navbar-reload"){ let videoCardList = $(parameter); videoCardList.each(function(i){ let href = $(this).children(".main-container").children("a").attr("href"); let videoCard = $(this); let videoCardTitle = $(this).attr("title") let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); }); } if(match == "video"){ let videoCardList = $(parameter).children(".video-page-card"); videoCardList.each(function(i){ let href = $(this).children(".card-box").children(".info").children("a").attr("href"); let videoCard = $(this); let videoCardTitle = $(this).children(".card-box").children(".info").children("a").children("span").attr("title"); let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); }); } if(match == "video-reload"){ let videoCardList = $(parameter); videoCardList.each(function(i){ let href = $(this).children(".card-box").children(".info").children("a").attr("href"); let videoCard = $(this); let videoCardTitle = $(this).children(".card-box").children(".info").children("a").children("span").attr("title"); let bvInfo = { bv : getBvcountber(href), index : i, card : videoCard, title : videoCardTitle, } loaded++; videoInfo.push(bvInfo); }); } return new Promise(function (isLoad) { let checkvideoInfo = setInterval(function () { $.each(videoInfo, function(i, v){ if(loaded == videoInfo.length){ clearInterval(checkvideoInfo); isLoad(true); } }); if (match == "home"){ if(loaded == videoInfo.length){ clearInterval(checkvideoInfo); isLoad(true); } } }, 500); }); } //==============video================ function initVideoListener(){ let index = 0; var targetNode = $('.rec-list')[0]; var options = {childList: true,attributes :true}; //console.log("init Video监听"); function callback(mutationsList, observer) { //console.log("callback Navbar监听"); if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length!=0 && isLoading == false){ //console.log("callback Video监听"); oldVideoInfo = videoInfo; videoInfo = []; isLoading = true let cardList = []; $.each(mutationsList, function(i, m){ cardList.push(m.addedNodes[0]); }); // console.log(cardList); Remove("video-reload","video",cardList); } } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); if(BiliBiliTagsBlocker.removeSpecialEnable){ if(BiliBiliTagsBlocker.onlyChangeColorEnable){ $($(targetNode).children("div")[0]).css({"background":"blue"}); } else { $($(targetNode).children("div")[0]).css({"display":"none"}); } } Remove("video","video",targetNode); } }, 50); } //接下来播放 function initNextVideoListener(){ var targetNode = $('#reco_list')[0] let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ let next = $(targetNode).children('.next-play') if (BiliBiliTagsBlocker.onlyChangeColorEnable) { next.css({"background":"blue"}) } else { next.css({"display":"none"}) } clearInterval(checkTarget); } }, 50); } //右下角推广 function removeRightBanner(){ var targetNode = $('#right-bottom-banner')[0]; let checkTarget = setInterval(function () { targetNode = $('#right-bottom-banner')[0]; if(targetNode != undefined && targetNode != null){ setTimeout(function(){ $("#right-bottom-banner").css("display","none"); },500); clearInterval(checkTarget); } }, 300); } //右下角直播 function removeLive(){ var targetNode = $('#live_recommand_report')[0]; let checkTarget = setInterval(function () { targetNode = $('#live_recommand_report')[0]; if(targetNode != undefined && targetNode != null){ $(targetNode).css({ "display": "none"}); clearInterval(checkTarget); } }, 300); } function removeBottomActivity(){ var targetNode = $('#activity_vote')[0]; let count = 0 let checkTarget = setInterval(function () { count += 1 targetNode = $('#activity_vote')[0]; if(targetNode != undefined && targetNode != null){ $(targetNode).css({ "display": "none"}); clearInterval(checkTarget); } if (count >= 10) { clearInterval(checkTarget); } }, 500); } //获取视频Tag信息 function initVideoTagInfo() { let loaded = false; $.each(videoInfo, function(i, b){ $.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid=BV"+b.bv, { method: 'GET', headers: { "content-type": "application/json" }, async: true, success: function (tags) { let tagInfo = { tags : tags } b["Tags"] = tagInfo; let r = { isRemove : false } b["isRemove"] = r; }, }); }); return new Promise(function (isLoad) { let checkTagsInfo = setInterval(function () { $.each(videoInfo, function(i, v){ if (v.hasOwnProperty("Tags") && v.Tags.hasOwnProperty("tags") && videoInfo[0].hasOwnProperty("isRemove")) { if (v.Tags.tags.hasOwnProperty("data")) { if(i == videoInfo.length-1){ clearInterval(checkTagsInfo); isLoad(true); } } } }); }, 500); }); } //设置需要删除的视频 function setRemoveVideo(){ let loaded = 0; $.each(videoInfo, function(i, v){ //if(loaded == 0){ //console.log(videoInfo); // } loaded++; if (v.hasOwnProperty("Tags") && v.Tags.hasOwnProperty("tags") && videoInfo[0].hasOwnProperty("isRemove")) { if (v.Tags.tags.hasOwnProperty("data") && v.Tags.tags.data.length > 0) { $.each(v.Tags.tags.data, function(i, t){ $.each(BiliBiliTagsBlocker.tagsArray, function(i, bt){ if(bt == t.tag_name){ let r = { isRemove : true } v["isRemove"] = r; } }); }); } } }); return new Promise(function (isLoad) { let checkTagsInfo = setInterval(function () { if (videoInfo.length == loaded) { clearInterval(checkTagsInfo); isLoad(true); } }, 500); }); } //删除网页中的视频 function removeVideo(match){ let zoom = detectZoom() $.each(videoInfo, function(i, v){ //console.log(v); //console.log(v.card.children(".info-box").children("a").children(".info").children(".title").text(i)); if(v.hasOwnProperty("isRemove") && v.isRemove.hasOwnProperty("isRemove") && !v.isRemove.isRemove && oldVideoInfo != videoInfo && match == "home"){ insertList.push(v); } if(v.hasOwnProperty("isRemove") && v.isRemove.hasOwnProperty("isRemove") && v.isRemove.isRemove && oldVideoInfo != videoInfo){ if(match == "popular"){ //console.log($(v.card)); if(BiliBiliTagsBlocker.onlyChangeColorEnable){ v.card.css({"background":"blue"}) }else{ v.card.remove(); } //console.log((v.index+1)+" "+ v.bv + " " + v.title); } if(match == "search"){ if(BiliBiliTagsBlocker.onlyChangeColorEnable){ v.context.css({"background":"blue"}) }else{ v.context.css({"display":"none"}); } } if(match == "post"){ //console.log(v.card); if(BiliBiliTagsBlocker.onlyChangeColorEnable){ v.color.css({"background":"blue"}) }else{ v.card.css({"display":"none"}); } } if(match == "home"){ if(BiliBiliTagsBlocker.onlyChangeColorEnable){ v.card.css({"background":"blue"}) }else{ removeCount++; removeList.push(v); v.card.css({"display":"none"}); //v.card.remove(); } } if(match == "navbar"){ //console.log(v); if(BiliBiliTagsBlocker.onlyChangeColorEnable){ v.card.css({"background":"blue"}) }else{ v.card.css({"display":"none"}); //v.card.css({"background":"blue"}) //v.card.remove(); } } if(match == "video"){ //console.log(v); if(BiliBiliTagsBlocker.onlyChangeColorEnable){ v.card.css({"background":"blue"}) }else{ v.card.css({"display":"none"}); //v.card.css({"background":"blue"}) //v.card.remove(); } } } }); if(match == "home" && !BiliBiliTagsBlocker.onlyChangeColorEnable){ $.each(insertList, function(i, v){ if(zoom < 100){ if(0 != i && 5 != i){ v.card.css({"margin-left":"10px"}) } } if(zoom >= 100 && zoom <= 135){ if(0 != i && 5 != i){ v.card.css({"margin-left":"10px"}) } } if(zoom >= 140 && zoom <= 150){ if(0 != i && 4 != i){ v.card.css({"margin-left":"10px"}) } } if(zoom > 150){ if(0 != i && 3 != i){ v.card.css({"margin-left":"10px"}) } } }) if(removeList.length >= 1){ $.each(removeList, function(i, v){ $($('.rcmd-box')[0]).append(v.card) }) } insertList = [] removeList = [] } } function Remove(init_match,remove_match,parameter){ isLoading = true; initvideoInfo(init_match,parameter).then(function (resolve) { initVideoTagInfo().then(function (resolve) { setRemoveVideo().then(function (resolve) { removeVideo(remove_match) if(BiliBiliTagsBlocker.homeCover && matchHome){ $('#cover').remove() } if(!home_first){ setTimeout(function(){ home_first = true },300); } if(matchHome){ setTimeout(function(){ isLoading = false; },300); }else{ isLoading = false; } }); }); }); } //视频板块监听器 function initBodyContainListener(){ var targetNode = $('.body-contain')[0]; //options:监听的属性 var options = {childList: true,attributes :true}; //回调事件 //console.log("init 板块监听"); function callback(mutationsList, observer) { if(currentSectionId != $(".body-contain").children("div").attr("id")) { currentSectionId = $(".body-contain").children("div").attr("id"); console.log("搜索区域变为"+currentSectionId); //console.log("板块监听 callback"); initSearchSectionListener(); initSearchListener() if(currentSectionId == "all-list" || currentSectionId == "video-list"){ setTimeout(function(){ oldVideoInfo = videoInfo; videoInfo = []; //SearchLoading() Remove("search","search",null); },1200); } } } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { currentSectionId = $(".body-contain").children("div").attr("id"); console.log("等待搜索区域"); targetNode = $('.body-contain')[0]; if(targetNode != undefined && targetNode != null && currentSectionId != undefined){ mutationObserver.observe(targetNode, options); console.log("搜索区域变为"+currentSectionId); // initSearchLoading() BUG initSearchSectionListener(); initSearchListener() //SearchLoading() BUG setTimeout(function(){ oldVideoInfo = videoInfo; videoInfo = []; Remove("search","search",null); },500); clearInterval(checkTarget); } }, 500); } //=======================热门页面========================= var f = 2; //设置监听器,监听新加载的视频 function initPopularListener(){ var targetNode = $('.card-list')[0]; //options:监听的属性 var options = {childList: true,subtree:true}; //回调事件 //console.log("init 热门监听"); function callback(mutationsList, observer) { //console.log(mutationsList); if(f == 2 && mutationsList[0].addedNodes.length != 0 && videoInfo.length >= 1 && isLoading == false){ let newCardList = []; //console.log("热门监听 callback"); $.each(mutationsList, function(i, v){ if(v.addedNodes.length!=0){ var newCard = $(v.addedNodes[0]); //newCard.css({"background":"blue"}) newCardList.push(newCard); } }); let checkNewCards = setInterval(function () { if (newCardList.length == 20){ videoInfo=[]; Remove("popular-reload","popular",newCardList) clearInterval(checkNewCards); } }, 500); } if(f == 2 &&mutationsList[0].addedNodes.length != 0 && videoInfo.length >= 1 && isLoading == true){ let newCardList = []; //console.log("热门监听 callback"); $.each(mutationsList, function(i, v){ if(v.addedNodes.length!=0){ var newCard = $(v.addedNodes[0]); //newCard.css({"background":"blue"}) newCardList.push(newCard); } }); let checkNewCards = setInterval(function () { if (newCardList.length == 20){ videoInfo=[]; setTimeout(function(){ Remove("popular-reload","popular",newCardList) },700); clearInterval(checkNewCards); } }, 500); } if(f == 1 && mutationsList[0].addedNodes.length != 0 && videoInfo.length >= 1 && isLoading == false){ videoInfo=[]; Remove("popular","popular",null) } if(f == 1 && mutationsList[0].addedNodes.length != 0 && videoInfo.length >= 1 && isLoading == true){ videoInfo=[]; setTimeout(function(){ Remove("popular","popular",null) },700); } } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); Remove("popular","popular",null) } }, 500); } //初始化加载动画 function initLoading(){ let g_loadingImage = 'https://pp-1252089172.cos.ap-chengdu.myqcloud.com/loading.gif'; $('.popular-list').prepend('