屏蔽bilibili的推荐
// ==UserScript==
// @name 屏蔽bilibili的推荐
// @namespace http://tampermonkey.net/
// @version 2024-04-23
// @description try to take over the world!
// @author You
// @match *://*.bilibili.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
blockIndexRecommend();
window.addEventListener("load",(event)=>{
console.info('网页加载完毕');
blockShiftedElement();
blockSearchInputRecommend();
})
function blockIndexRecommend(){
console.info('屏蔽首页推荐');
const feed4Layout = document.querySelector(".bili-feed4-layout");
if(feed4Layout){
feed4Layout.style.display="none";
}
}
function blockShiftedElement(){
const headerChannel = document.querySelector(".header-channel");
if(headerChannel){
headerChannel.style.position = "absolute";
headerChannel.style.visibility="hidden";
headerChannel.style.display = "none !important";
}
}
function bindEvent(element, type, fn){
element.addEventListener(type, fn);
}
function blockTrending(){
let countTimer = 3000; // 3秒未查出也清除定时器
const delayTime = 500;
let timer = setInterval(()=>{
countTimer = countTimer - delayTime;
const trendingEle = document.querySelector(".trending");
console.info(trendingEle);
if(trendingEle){
trendingEle.style.display="none";
clearInterval(timer);
}
if(countTimer<0){
clearInterval(timer);
}
},delayTime)
}
function tryToGetSearchInput(){
return new Promise((resolve, reject)=>{
let totalTime = 3000;
let delayTime = 10;
let searchInput = null;
let timer = setInterval(()=>{
totalTime = totalTime - delayTime;
searchInput = document.querySelector('.nav-search-input');
if(searchInput){
resolve(searchInput);
clearInterval(timer);
}
if(totalTime<0){
resolve(searchInput);
clearInterval(timer);
}
}, delayTime);
})
}
async function blockSearchInputRecommend(){
console.info('屏蔽搜索栏推荐');
let searchInput = await tryToGetSearchInput();
if(location.host==="search.bilibili.com"){
searchInput = document.querySelector('.search-input-el');
}
console.log(searchInput);
if(searchInput){
bindEvent(searchInput, 'click', ()=>{
blockTrending();
})
bindEvent(searchInput, 'input',(event)=>{
if(event.target.value === ""){
blockTrending();
}
})
bindEvent(searchInput, 'change',(event)=>{
blockTrending();
})
}
}
// Your code here...
const biliBody = document.body;
const divElement = document.createElement("div");
divElement.innerText = "看真正有用的东西!";
divElement.style.fontSize = "48px";
divElement.style.color = "#ffaaaa";
divElement.style.textAlign = "center";
divElement.style.margin = "20px auto";
biliBody.appendChild(divElement);
})();