// ==UserScript== // @name BiliBili Tags Blocker BiliBili标签屏蔽助手 // @namespace https://greasyfork.org/zh-CN/users/924205-xiao-xi // @version 0.4.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://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, 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.5', type: 's', }, { id: 'functionEnable', label: '启用屏蔽功能', title: '总开关', type: 'c', default: true, }, { id: 'removeSpecialEnable', label: '移除特别推荐', title: '多为推广', type: 'c', default: false, }, { id: 'removeNextVideo', label: '移除接下来播放', title: '推荐的什么jb', type: 'c', default: false, }, { id: 'onlyChangeColorEnable', label: '看看屏蔽了什么', title: '更改屏蔽视频的背景色', type: 'c', default: false, move_right: true, }, { id: 'homeCover', label: '首页遮罩', title: '加载图', 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); } //获取视频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){ //console.log(videoInfo); let count = 0 $.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" && removeCount >= 1){ $.each(removeList, function(i, v){ count++ if(v.index < 5){ //console.log(v); //console.log("================"); let num = 6-v.index; for (let i = 1; num >= i; i++) { //console.log(insertList[insertList.length-i]); setTimeout(function(){ $('.rcmd-box').prepend(insertList[insertList.length-i].card); },100); } } }) } } 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('
'); $("head").append(''); $(".card-list").css({'display': 'none'}); $(document).scrollTop(0); } //进行加载动画 function Loading(){ $("#loading").css({'display': 'block'}); $(".card-list").css({'display': 'none'}); $(document).scrollTop(0); } //停止加载动画 function stopLoading(){ $("#loading").css({'display': 'none'}); $(".card-list").css({'display': 'flex'}); $(document).scrollTop(scrollTop) } //==================搜索页面======================= function disConnectListener(){ //console.log(33333333333); //videoListListener.disconnect(); } //初始化加载动画 function initSearchLoading(){ let g_loadingImage = 'https://pp-1252089172.cos.ap-chengdu.myqcloud.com/loading.gif'; $('.body-contain').children("div").prepend('
'); //$("head").append(''); $(".video-list").css({'display': 'none'}); //$(document).scrollTop(0); } //进行加载动画 function SearchLoading(){ $("#loadingSearch").css({'display': 'block'}); $(".video-list").css({'display': 'none'}); //$(document).scrollTop(0); } //停止加载动画 function stopSearchLoading(){ $("#loadingSearch").css({'display': 'none'}); $(".video-list").css({'display': 'block'}); //$(document).scrollTop(scrollTop) } //页码监听 function initSearchListener(){ var targetNode = $('.flow-loader')[0]; //options:监听的属性 var options = {childList: true,attributes :true}; //回调事件 //console.log("init 页码监听"); let count = 0; function callback(mutationsList, observer) { if(mutationsList[0].addedNodes.length!=0 && videoInfo.length>=20 && isLoading == false) { //console.log("页码监听 callback"); initSearchSectionListener() $.each(mutationsList, function(i, m){ if(m.addedNodes[0] != undefined && m.addedNodes[0] != null){ if(m.addedNodes[0].className != undefined && m.addedNodes[0].className != null){ let newSearchItemList = $(m.addedNodes[0]) newSearchItemList.each(function(i){ let c = $($(this)[0])[0].className.split(" "); if(c.includes("video-list") && videoInfo != oldVideoInfo){ count = 0; oldVideoInfo = videoInfo; videoInfo = []; isLoading = true; //加载中 Remove("search-reload","search",newSearchItemList.children()) }else{ } }); } if(isLoading == false && count > mutationsList.length){ count = 0; isLoading = true; //加载中 oldVideoInfo = videoInfo; videoInfo = []; Remove("search-reload","search",$(".video-item")) } } count++ }); } } var mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); } }, 500); } //选项监听 function initSearchSectionListener(){ var targetNode = $('.video-list')[0]; //options:监听的属性 var options = {childList: true,attributes :true}; //回调事件 //console.log("init 选项监听"); function callback(mutationsList, observer) { //console.log("选项监听 callback"); oldVideoInfo = videoInfo; videoInfo = []; Remove("search","search",null); } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); } }, 500); } //==================动态======================= var postMode; // 切换 全部动态/UP 监听 function initPostChangeListener(){ let index = 0; var targetNode = $('section')[index]; var options = {childList: true,attributes :true}; //console.log("init 切换动态/UP 监听"); function callback(mutationsList, observer) { //console.log("callback 全部动态/UP"); if($(targetNode).children()[0].className == "bili-dyn-list-tabs" || $(targetNode).children()[0].className == "bili-dyn-list"){ postMode = $(targetNode).children()[0].className } oldVideoInfo = videoInfo; videoInfo = []; setTimeout(function(){ initPostListener() },500); } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ //console.log(targetNode); if($(targetNode).children()[0].className == "bili-dyn-list-tabs" || $(targetNode).children()[0].className == "bili-dyn-list"){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); initPostListener(); } else{ index+=1; targetNode = $('section')[index]; } } }, 50); } //全部/视频投稿监听 function initPostListener(){ var targetNode = $('.bili-dyn-list__items')[0]; var options = {childList: true,attributes :true}; //console.log("init 动态监听"); function callback(mutationsList, observer) { if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length!=0 && isLoading == false){ //console.log("动态监听 callback"); oldVideoInfo = videoInfo; videoInfo = []; isLoading = true let cardList = []; $.each(mutationsList, function(i, m){ cardList.push(m.addedNodes[0]); }); //console.log(cardList); Remove("post-reload","post",cardList); } if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length!=0 && isLoading == true){ //console.log("动态监听 callback2"); setTimeout(function(){ oldVideoInfo = videoInfo; videoInfo = []; isLoading = true let cardList = []; $.each(mutationsList, function(i, m){ cardList.push(m.addedNodes[0]); }); //console.log(cardList); Remove("post-reload","post",cardList); },600); } if(mutationsList.length >= 1 && mutationsList[0].removedNodes.length!=0 && isLoading == false){ // console.log("动态监听 callback3"); oldVideoInfo = videoInfo; videoInfo = []; isLoading = true setTimeout(function(){ Remove("post","post",null); },500); } if(postMode == "bili-dyn-list" && isLoading == false){ // console.log("动态监听 up"); oldVideoInfo = videoInfo; videoInfo = []; isLoading = true setTimeout(function(){ Remove("post","post",null); },800); } } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); Remove("post","post",null); } }, 500); } //==================首页======================= var insertList = []; var removeList = []; var removeCount = 0; var home_first = false; function initHomeListener(){ var targetNode = $('.rcmd-box')[0]; var options = {childList: true,attributes :true}; //console.log("init 首页监听"); function callback(mutationsList, observer) { // console.log('home_first -> '+ home_first); //console.log('isLoading -> '+ isLoading); $.each(mutationsList, function(i, m){ if(m.addedNodes.length!=0 && isLoading == false && home_first == true) { // console.log("callback 首页监听"); isLoading = true; oldVideoInfo = videoInfo; videoInfo = []; setTimeout(function(){ Remove("home","home",null); },300); } }) } let src = 'https://s2.loli.net/2022/08/04/G1YVrxT6vCsPgBW.jpg' let first = true let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null && first){ if(BiliBiliTagsBlocker.homeCover){ let w = $($('.rcmd-box-wrap')[0]).width() let h = $($('.rcmd-box-wrap')[0]).height() $($('.rcmd-box-wrap')[0]).prepend(''); $(".change-btn").click(function(){ //alert("EventListener success!"); let w = $($('.rcmd-box-wrap')[0]).width() let h = $($('.rcmd-box-wrap')[0]).height() $($('.rcmd-box-wrap')[0]).prepend(''); }); } first = false Remove("home","home",null); } if(home_first){ mutationObserver.observe(targetNode, options); clearInterval(checkTarget); } }, 500); } //==================navbar==================== function initNavbarListener(){ let index = 0; var targetNode = $('.video-list')[0]; var options = {childList: true,attributes :true}; //console.log("init Navbar监听"); function callback(mutationsList, observer) { //console.log("callback Navbar监听"); if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length!=0 && isLoading == false){ //console.log("动态监听 callback"); oldVideoInfo = videoInfo; videoInfo = []; isLoading = true let cardList = []; $.each(mutationsList, function(i, m){ cardList.push(m.addedNodes[0]); }); //console.log(cardList); Remove("navbar-reload","navbar",cardList); } } let mutationObserver = new MutationObserver(callback); let checkTarget = setInterval(function () { if(targetNode != undefined && targetNode != null){ //console.log(targetNode); mutationObserver.observe(targetNode, options); clearInterval(checkTarget); Remove("navbar","navbar",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); } //let checkTarget = setInterval(function () { //console.log($('.video-list')[0]); //}, 500); //通过url获得BV号 function getBvcountber(video_link) { let bvcount = ''; try { bvcount = /\/video\/(?:av|bv)(\w+)/i.exec(video_link)[1]; } catch (e) { bvcount = null; } return bvcount; } //检查jQuery var checkJQuery = function () { let jqueryCdns = [ 'http://code.jquery.com/jquery-2.1.4.min.js', 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', 'https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js', 'https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js', ]; function isJQueryValid() { try { let wd = unsafeWindow; if (wd.jQuery && !wd.$) { wd.$ = wd.jQuery; } $(); return true; } catch (exception) { return false; } } function insertJQuery(url) { setTimeout(function(){ let checkJQuery = setInterval(function () { if(document == undefined && document != null && document.createElement('script') == undefined && document.createElement('script') != null){ let script = document.createElement('script'); script.src = url; document.head.appendChild(script); return script; clearInterval(checkJQuery); } }, 100); },500); } function converProtocolIfNeeded(url) { let isHttps = location.href.indexOf('https://') != -1; let urlIsHttps = url.indexOf('https://') != -1; return script; if (isHttps && !urlIsHttps) { return url.replace('http://', 'https://'); } else if (!isHttps && urlIsHttps) { return url.replace('https://', 'http://'); } return url; } function waitAndCheckJQuery(cdnIndex, resolve) { if (cdnIndex >= jqueryCdns.length) { iLog.e('无法加载 JQuery,正在退出。'); resolve(false); return; } let url = converProtocolIfNeeded(jqueryCdns[cdnIndex]); iLog.i('尝试第 ' + (cdnIndex + 1) + ' 个 JQuery CDN:' + url + '。'); let script = insertJQuery(url); setTimeout(function () { if (isJQueryValid()) { iLog.i('已加载 JQuery。'); resolve(true); } else { iLog.w('无法访问。'); script.remove(); waitAndCheckJQuery(cdnIndex + 1, resolve); } }, 100); } return new Promise(function (resolve) { if (isJQueryValid()) { iLog.i('已加载 jQuery。'); resolve(true); } else { iLog.i('未发现 JQuery,尝试加载。'); waitAndCheckJQuery(0, resolve); } }); } let checkSetting = setInterval(function () { BiliBiliTagsBlocker = blockObj.getConfig(); if(BiliBiliTagsBlocker.tagsArray != null){ clearInterval(checkSetting); } }, 500); function ILog() { this.prefix = ''; this.v = function (value) { if (level <= this.LogLevel.Verbose) { console.log(this.prefix + value); } } this.i = function (info) { if (level <= this.LogLevel.Info) { console.info(this.prefix + info); } } this.w = function (warning) { if (level <= this.LogLevel.Warning) { console.warn(this.prefix + warning); } } this.e = function (error) { if (level <= this.LogLevel.Error) { console.error(this.prefix + error); } } this.d = function (element) { if (level <= this.LogLevel.Verbose) { console.log(element); } } this.setLogLevel = function (logLevel) { level = logLevel; } this.LogLevel = { Verbose: 0, Info: 1, Warning: 2, Error: 3, }; let level = this.LogLevel.Verbose; } let isCheckSetting = false; let inChecking = false; let matchSuccess = false; let jqItv = setInterval(function () { if (inChecking) { return; } inChecking = true; checkJQuery().then(function (isLoad) { if (isLoad) { initSettingUI() if(BiliBiliTagsBlocker.functionEnable){ console.log("已启用Tags屏蔽"); }else{ console.log("已关闭Tags屏蔽"); } if (BiliBiliTagsBlocker.functionEnable) { initNavbarListener(); } if (matchSearch && BiliBiliTagsBlocker.functionEnable && !matchSuccess) { matchSuccess = true; initBodyContainListener(); initSearchListener(); initSearchSectionListener(); Remove("search","search",null); } if (matchPopular && BiliBiliTagsBlocker.functionEnable && !matchSuccess) { matchSuccess = true; initPopularListener() } if (matchPost && BiliBiliTagsBlocker.functionEnable && !matchSuccess) { matchSuccess = true; initPostChangeListener() } if (matchVideo && BiliBiliTagsBlocker.functionEnable && !matchSuccess) { matchSuccess = true; initVideoListener() if(BiliBiliTagsBlocker.removeNextVideo){ initNextVideoListener() } } if (matchHome && BiliBiliTagsBlocker.functionEnable && !matchSuccess) { matchSuccess = true; initHomeListener() } if(BiliBiliTagsBlocker.functionEnable != undefined){ clearInterval(jqItv); } } inChecking = false; }); }, 500); var iLog = new ILog();