// ==UserScript==
// @name BiliBili Tags Blocker BiliBili标签屏蔽助手
// @namespace https://gf.qytechs.cn/zh-CN/users/924205-xiao-xi
// @version 0.7.0
// @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/[email protected]/dist/ajaxhook.min.js
// @require https://cdn.jsdelivr.net/npm/[email protected]/minified/arrive.min.js
// @require https://gf.qytechs.cn/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
// ==/UserScript==
// https://gf.qytechs.cn/zh-CN/scripts/417760-checkjquery
var BiliBiliTagsBlocker = {
functionEnable: true,
onlyChangeColorEnable: false,
removeSpecialEnable: false,
removeNextVideo: false,
homeCover: false,
removeSearchTrend: false,
removeRightBanner: false,
removeLive: false,
removeBottomActivity: false,
blurMode: false,
hiddenMode: false,
tagsArray: [],
};
const BASIC_STYLE = `
.block_obj_checkbox_label {
padding-left: 13px;
}
`;
let blockObj = new Block_Obj('BiliBili_Tags_Blocker');
document.arrive("body", { fireOnAttributesModification: true, onceOnly: true, existing: true }, function() {
initSettingUI()
});
function initSettingUI(){
blockObj.init({
id: 'BiliBiliTagsBlocker',
menu: 'Tags屏蔽设置',
style: BASIC_STYLE,
field: [
{
id: 'version',
label: 'v0.7.0',
type: 's',
},
{
id: 'functionEnable',
label: '启用屏蔽功能',
title: '总开关',
type: 'c',
default: true,
},
{
id: 'onlyChangeColorEnable',
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: 'homeCover',
label: '首页遮罩(暂时移除)',
title: '加载图',
type: 'c',
default: false,
},
{
label: '搜索页设置',
type: 's',
},
{
id: 'removeSearchTrend',
label: '移除热搜栏',
title: '推荐的什么jb',
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',
},
{
id: 'tagsArray',
type: 'l',
default: [],
},
],
events: {
save: config => {
BiliBiliTagsBlocker = config;
},
change: config => {
BiliBiliTagsBlocker = config;
},
},
})
}
//视频信息
var videoInfo = [];
let href = location.href;
let matchSearch = href.match(/search.bilibili/);
let matchPopular = href.match(/popular/);
let matchRank = href.match(/\/popular\/rank/);
let matchPost = href.match(/t.bilibili/);
let matchVideo = href.match(/video/);
let matchHome = href.match(/bilibili.com/);
//==============视频页================
function initVideoListener(){
var targetNode = $('.rec-list')[0];
var options = {childList: true};
function callback(mutationsList, observer) {
if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length!=0){
$.each(mutationsList, function(i, m){
initvideoInfo(m.addedNodes[0])
});
}
}
let mutationObserver = new MutationObserver(callback);
let checkTarget = setInterval(function () {
targetNode = $('.rec-list')[0];
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
{
if(BiliBiliTagsBlocker.blurMode){
$($(targetNode).children("div")[0]).css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
$($(targetNode).children("div")[0]).css({"display":"none"});
}
}
}
$.each($(targetNode).children(".video-page-card"), function(i, m){
initvideoInfo(m)
});
}
}, 50);
}
function initvideoInfo(card){
let href = $(card).children(".card-box").children(".info").children("a").attr("href");
let videoCard = $(card);
let bv = getBvcountber(href)
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
videoCard.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
videoCard.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
videoCard.css({"display":"none"});
}
}
successed = true
}
})
})
},
});
}
//接下来播放
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);
}
//推广视频
function removeAdVideo(){
setTimeout(function(){
$('.video-ad-creative-card').remove()
},500);
}
//=======================热门页面=========================
function initPopularVideoInfo(url){
videoInfo = []
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){
if(num != 1){
if(BiliBiliTagsBlocker.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 bvInfo = {
bv : "BV"+getBvcountber(href),
card : videoCard,
}
videoInfo.push(bvInfo);
if(videoInfo.length > 0){
clearInterval(checkTarget);
}
});
}
}, 50);
let checkTarget1 = setInterval(function () {
if(videoInfo.length > 0 && BiliBiliTagsBlocker.tagsArray != null && BiliBiliTagsBlocker.tagsArray != undefined && BiliBiliTagsBlocker.tagsArray.length >= 1){
$.each(videoInfo, function(i, v){
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+v.bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
v.card.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
v.card.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
v.card.remove();
}
}
successed = true
}
})
})
},
});
});
clearInterval(checkTarget1);
}
}, 50);
}
//=======================排行榜=========================
function initRankVideoInfo(){
let videoInfo = [];
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 () {
let videoCardList = $(".rank-item");
if(videoCardList != null && videoCardList != undefined){
videoCardList.each(function(i){
let href = $(this).children(".content").children(".info").children("a").attr("href");
let videoCard = $(this);
let bvInfo = {
bv : "BV"+getBvcountber(href),
card : videoCard,
}
videoInfo.push(bvInfo);
if(videoInfo.length > 99){
//console.log(videoInfo)
clearInterval(checkTarget);
}
});
}
}, 50);
let checkTarget1 = setInterval(function () {
if(videoInfo.length > 99 && BiliBiliTagsBlocker.tagsArray != null && BiliBiliTagsBlocker.tagsArray != undefined && BiliBiliTagsBlocker.tagsArray.length >= 1){
$.each(videoInfo, function(i, v){
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+v.bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
v.card.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
v.card.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
v.card.remove();
}
}
successed = true
}
})
})
},
});
});
clearInterval(checkTarget1);
}
}, 50);
}
}
//==================搜索页面=======================
var videoInfo2 = []
//推广视频
function removeTrend(){
setTimeout(function(){
$('.home-suggest').remove()
},300);
}
//手动请求ajax
function clickSearchAgain(){
//$('.page-item.active').children('button').click()
//console.log($('.page-item.active').children('button'))
$('div.search-button').click()
}
function initSearchVideoInfo(){
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 card = {
tags: tags,
typeName: typeName,
card: $(v)
};
videoInfo2.push(card)
})
let checkTarget = setInterval(function () {
if(videoInfo2.length > 19){
removeSearchVideo()
clearInterval(checkTarget);
}
}, 50);
}
function removeSearchVideo(){
$.each(videoInfo2, function(i, v){
let successed = false;
$.each(v.tags, function(i1, tag){
if((BiliBiliTagsBlocker.tagsArray.includes(tag) || BiliBiliTagsBlocker.tagsArray.includes(v.typeName)) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
v.card.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
v.card.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
v.card.css({"display":"none"});
}
}
successed = true
}
});
});
videoInfo2 = []
responses = []
}
function removeUserVideo(){
let userVideoInfo = []
let videoListCard = $('.u-videos').children('.video-item')
videoListCard.each(function(i,v){
let href = $(v).children('a').attr('href')
let videoCard = $(this);
let bvInfo = {
bv : 'BV'+getBvcountber(href),
card : videoCard,
}
userVideoInfo.push(bvInfo)
})
let checkTarget = setInterval(function () {
if(userVideoInfo.length > 0 && BiliBiliTagsBlocker.tagsArray != null && BiliBiliTagsBlocker.tagsArray != undefined && BiliBiliTagsBlocker.tagsArray.length >= 1){
$.each(userVideoInfo, function(i, v){
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+v.bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
v.card.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
v.card.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
v.card.css({"display":"none"});
}
}
successed = true
}
})
})
},
});
});
clearInterval(checkTarget);
}
}, 50);
}
//==================动态=======================
function initPostVideoInfo(){
videoInfo = []
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"+bv,
card : $(this),
color : videoCard,
title : "",
}
videoInfo.push(bvInfo);
}
});
let checkTarget = setInterval(function () {
if(videoInfo.length > 0 && BiliBiliTagsBlocker.tagsArray != null && BiliBiliTagsBlocker.tagsArray != undefined && BiliBiliTagsBlocker.tagsArray.length >= 1){
$.each(videoInfo, function(i, v){
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+v.bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
v.color.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
v.color.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
v.color.css({"display":"none"});
}
}
successed = true
}
})
})
},
});
});
clearInterval(checkTarget);
}
}, 50);
}
//==================首页=======================
function clickChangeAgain(){
//$('.page-item.active').children('button').click()
//console.log($('.page-item.active').children('button'))
$('div.change-btn').click()
}
function initHomeVideoInfo(videoList){
videoInfo = []
let insertList1 = []
if(!BiliBiliTagsBlocker.onlyChangeColorEnable){
setTimeout(function(){
$($('.rcmd-box')[0]).css({"justify-content":"flex-start"})
},100);
}
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 : 'BV'+getBvcountber(href),
card : videoCard,
title : videoCardTitle
}
videoInfo.push(bvInfo);
}
});
let checkTarget = setInterval(function () {
if(videoInfo.length > 0 && BiliBiliTagsBlocker.tagsArray != null && BiliBiliTagsBlocker.tagsArray != undefined && BiliBiliTagsBlocker.tagsArray.length >= 1){
$.each(videoInfo, function(i, v){
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+v.bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
v.card.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
v.card.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
v.card.css({"display":"none"});
}
}
successed = true
}
})
})
if(!successed && !BiliBiliTagsBlocker.onlyChangeColorEnable){
insertList1.push(v)
$($('.rcmd-box')[0]).prepend(v.card)
}
},
});
});
clearInterval(checkTarget);
}
}, 50);
if(!BiliBiliTagsBlocker.onlyChangeColorEnable){
let zoom = detectZoom()
let insertList2 = []
let reverse = function(){
return new Promise(function(resolve){
let checkTarget1 = setInterval(function () {
if(insertList1.length > 0){
$.each(insertList1, function(i, v){
insertList2.push(insertList1[insertList1.length-1-i])
})
clearInterval(checkTarget1);
resolve(true);
}
}, 350);
});
}
reverse().then(function(data){
$.each(insertList2, 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){
//console.log(i + " " + v.title)
v.card.css({"margin-left":"10px"})
}
}
})
})
}
}
//==================动态导航栏====================
function initNavbarListener(){
var targetNode = $('.video-list')[0];
var options = {childList: true,attributes :true};
function callback(mutationsList, observer) {
if(mutationsList.length >= 1 && mutationsList[0].addedNodes.length!=0){
$.each(mutationsList, function(i, m){
initNavbarVideoInfo(m.addedNodes[0])
});
}
}
let mutationObserver = new MutationObserver(callback);
let checkTarget = setInterval(function () {
if(targetNode != undefined && targetNode != null){
mutationObserver.observe(targetNode, options);
clearInterval(checkTarget);
$.each($(targetNode).children(".list-item"), function(i, m){
initNavbarVideoInfo(m)
});
}
}, 50);
}
function initNavbarVideoInfo(card){
let href = $(card).children(".main-container").children("a").attr("href");
let videoCard = $(card);
let bv = getBvcountber(href)
$.ajax("https://api.bilibili.com/x/web-interface/view/detail/tag?bvid="+bv, {
method: 'GET',
headers: {
"content-type": "application/json"
},
async: true,
success: function (tags) {
let successed = false;
$.each(tags.data,function(i,t){
$.each(t,function(i,tag){
if(BiliBiliTagsBlocker.tagsArray.includes(t.tag_name) && !successed) {//includes 检测数组是否有某个值
if(BiliBiliTagsBlocker.onlyChangeColorEnable){
videoCard.css({"background":"blue"})
}else{
if(BiliBiliTagsBlocker.blurMode){
videoCard.css({"filter":"blur(1rem)"});
}
if(BiliBiliTagsBlocker.hiddenMode){
videoCard.remove();
}
}
successed = true
}
})
})
},
});
}
//==================other====================
//重设界面
//0,收起 1,展开
var buttonState = 0
var responses = []
function reSetUI(){
//$('#blockObj_BiliBiliTagsBlocker_mainFieldset').css({"background-color":""})
$($('#blockObj_BiliBiliTagsBlocker_ulNode')[0]).append('<span id="cancel2" class="block_obj_button" style="float: left;margin-left: 5px;">取消<span/>');
let parent = $($('#blockObj_BiliBiliTagsBlocker_version')[0]).parent()
parent.css("display","flex")
parent.append('<span class="block_obj_separator_text" style="">当前共屏蔽'+ BiliBiliTagsBlocker.tagsArray.length +'个标签<span/>')
let ver = $($('#blockObj_BiliBiliTagsBlocker_version')[0])
ver.css("width","73%")
let count = 0
let expand = $($(".block_obj_input_btn")[4])
let targetNode = $($('.block_obj_list_textarea_div')[0]);
let checkTarget = setInterval(function () {
expand = $($(".block_obj_input_btn")[4])
if(targetNode != undefined && targetNode != null){
targetNode.css('max-height','69')
if(expand.attr("title") == '展开列表'){
expand.click(function(){
count += 1
if(buttonState == 0){
targetNode.animate({
maxHeight: 300, opacity: 'show'
}, "slow");
}
if(buttonState == 1){
targetNode.animate({
maxHeight: 69, opacity: 'show'
}, "slow");
}
if(buttonState == 0){
buttonState = 1
}
else{
buttonState = 0
}
});
}
clearInterval(checkTarget);
}
}, 50);
let cancel2 = $($("#cancel2")[0])
$($('.block_obj_button')[2]).remove()
cancel2.click(function(){
let main = $($("#blockObj_BiliBiliTagsBlocker_wrapDiv")[0])
main.removeClass('block_obj_wrap_div block_obj_show_wrap')
main.addClass('block_obj_wrap_div block_obj_hidden_wrap')
});
if (window.parent == window) {
// 当前页面不在iframe中
}
else
{
// 当前页面在iframe或者frameset中
$("#blockObj_BiliBiliTagsBlocker_expandSpan").animate({
opacity: 'hide'
}, 200);
}
}
if (window.parent == window) {
// 当前页面不在iframe中
ajaxHook();
}
else
{
// 当前页面在iframe或者frameset中
}
function ajaxHook() {
ah.proxy(
{
onResponse: (response, handler) => {
//搜索页 例/all?keyword=原神
if (!response.config.url.includes('/web-interface/search/default') && response.config.url.includes('/web-interface/search')){
let data = JSON.parse(response.response).data
if(data.result.length == 11){
responses.push(data.result[data.result.length-1])
}
if(data.result.length == 20){
let data1 = {
data: data.result,
result_type: 'video'
}
responses.push(data1)
}
initSearchVideoInfo()
setTimeout(function(){
removeUserVideo()
},100);
}
//热门页面
if (response.config.url.includes('/web-interface/popular')){
initPopularVideoInfo(response.config.url)
}
//排行榜
if (response.config.url.includes('rank')){
let data = JSON.parse(response.response);
initRankVideoInfo()
}
//首页
if (response.config.url.includes('web-interface/index/top/rcmd')){
let data = JSON.parse(response.response).data;
setTimeout(function(){
initHomeVideoInfo(data.item)
},50);
}
//动态
if (response.config.url.includes('web-dynamic/v1/feed/all')){
setTimeout(function(){
initPostVideoInfo()
},50);
}
handler.next(response);
},
},
unsafeWindow
);
}
//通过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;
}
//获取当前缩放比例
function detectZoom() {
var ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}
else if (~ua.indexOf('msie')) {
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI;
}
}
else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth;
}
if (ratio) {
ratio = Math.round(ratio * 100);
}
return ratio;
}
//检查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)
{
if(BiliBiliTagsBlocker.functionEnable){
console.log("已启用Tags屏蔽");
initNavbarListener();
}else{
console.log("已关闭Tags屏蔽");
}
if (matchSearch && BiliBiliTagsBlocker.functionEnable && !matchSuccess) {
matchSuccess = true;
if(BiliBiliTagsBlocker.removeSearchTrend){
removeTrend();
}
clickSearchAgain();
}
if (matchVideo && BiliBiliTagsBlocker.functionEnable && !matchSuccess) {
matchSuccess = true;
initVideoListener()
if(BiliBiliTagsBlocker.removeNextVideo){
initNextVideoListener()
}
if(BiliBiliTagsBlocker.removeRightBanner){
removeRightBanner()
}
if(BiliBiliTagsBlocker.removeLive){
removeLive()
}
if(BiliBiliTagsBlocker.removeBottomActivity){
removeBottomActivity()
}
removeAdVideo()
}
if (matchRank && BiliBiliTagsBlocker.functionEnable && !matchSuccess) {
matchSuccess = true;
initRankVideoInfo()
}
if (matchHome && BiliBiliTagsBlocker.functionEnable && !matchSuccess) {
matchSuccess = true;
clickChangeAgain()
}
if(BiliBiliTagsBlocker.functionEnable != undefined){
reSetUI()
clearInterval(jqItv);
}
}
inChecking = false;
});
}, 500);
var iLog = new ILog();