您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
隐藏直播卡片遮罩,隐藏底部弹幕,全部直播间页面隐藏聊天室直播间
// ==UserScript== // @name NYJX - bilibili // @namespace https://www.bilibili.com/ // @version 0.2.0 // @description 隐藏直播卡片遮罩,隐藏底部弹幕,全部直播间页面隐藏聊天室直播间 // @author 能用就行 // @match *://*.bilibili.com/* // @icon https://www.bilibili.com/favicon.ico // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @license MIT // ==/UserScript== (function() { 'use strict'; GM_addStyle(` /* 聊天室直播卡片 */ #card[data-test="true_1"], /* 底部弹幕 */ .bili-danmaku-x-center, /* 直播卡片遮罩 */ [class^="Item_player-mask_"], /* 直播logo */ .web-player-icon-roomStatus, /* 底部广告 */ .left-container .flip-view.p-relative.over-hidden, /* 动态页广告 */ .bili-dyn-ads, /* 顶栏 下载客户端 */ .download-entry.download-client-trigger, /* 广告屏蔽插件提示 */ .adblock-tips { display: none !important; } /* 直播马赛克 */ #web-player-module-area-mask-panel { opacity: 0; } `) let batchTimeout = null; var jc_room_id_list = GM_getValue('jc_room_id_list', []); var yc_room_id_list = GM_getValue('yc_room_id_list', ["1919214962","1710489753"]); // 电竞?陪玩? 还是聊天室√ 因为不在聊天室分区 特此添加 function 设置状态() { const bs = document.querySelectorAll('#card'); bs.forEach(b => { const href = b.getAttribute('href'); const room_id_match = href.match(/\/(\d+)\?/); let room_id; if (room_id_match) { room_id = room_id_match[1]; } else { console.error('无法从链接中提取room_id:', href); return; } if (jc_room_id_list.includes(room_id)) { b.setAttribute('data-test', 'true_0'); b.parentElement.setAttribute('data-test', 'true_0'); } if (yc_room_id_list.includes(room_id)) { b.setAttribute('data-test', 'true_1'); b.parentElement.setAttribute('data-test', 'true_1'); } }); console.log('设置状态一次'); } function 设置属性() { const as = document.querySelectorAll('#card'); as.forEach(a => { a.setAttribute('data-test', 'false'); }); console.log('初始化一次'); } async function 检查() { const cards = document.querySelectorAll('#card[data-test="false"]'); let fetchPromises = []; cards.forEach(card => { const href = card.getAttribute('href'); const room_id_match = href.match(/\/(\d+)\?/); let room_id; if (room_id_match) {room_id = room_id_match[1];} else {console.error('无法从链接中提取room_id:', href);return;} if (!jc_room_id_list.includes(room_id) && !yc_room_id_list.includes(room_id)) { const params = new URLSearchParams({room_id: room_id}); const url = `https://api.live.bilibili.com/room/v1/Room/get_info?${params.toString()}`; fetchPromises.push( fetch(url, { method: 'GET', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Edg/126.0.0.0' } }) .then(response => response.json()) .then(data => { if (data.data.parent_area_name === "聊天室") { console.warn('发现聊天室', room_id); if (!jc_room_id_list.includes(room_id)) {jc_room_id_list.push(room_id);} if (!yc_room_id_list.includes(room_id)) {yc_room_id_list.push(room_id);} } else { console.log('非聊天室:', room_id); if (!jc_room_id_list.includes(room_id)) {jc_room_id_list.push(room_id);} } }) .catch(error => { console.error('Error:', error); }) ); } }); await Promise.all(fetchPromises); GM_setValue('jc_room_id_list', jc_room_id_list); GM_setValue('yc_room_id_list', yc_room_id_list); console.log('储存一次'); 设置状态(); } function executeWithRetry(conditionSelector, action, retryInterval = 1000) { const conditionElement = document.querySelector(conditionSelector); if (conditionElement) { console.log(`${conditionSelector} 已找到,开始执行操作...`); action(); } else { console.log(`${conditionSelector} 未找到,稍后重试...`); setTimeout(() => executeWithRetry(conditionSelector, action, retryInterval), retryInterval); } } function onElementAdded() { console.log('检测到 #room-card-list 增加了新元素!'); 设置属性(); 设置状态(); 检查(); const roomCardList = document.querySelector('#room-card-list'); if (roomCardList) { console.log('当前子元素列表:', roomCardList.children); } } const observer = new MutationObserver((mutationsList) => { for (const mutation of mutationsList) { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { clearTimeout(batchTimeout); batchTimeout = setTimeout(onElementAdded, 800); } } }); const config = { childList: true, subtree: false }; const path = window.location.pathname; const roomId = path.substring(1).split('/')[0]; if (/^\d+$/.test(roomId)) { console.log("这是一个有效的直播间页面,房间号:" + roomId); } else { console.log("这不是一个有效的直播间页面"); } if (path === '/all') { console.log("当前在全部直播间页"); // 初始化 executeWithRetry('#card', () => { console.log('#card 已找到,开始执行初始化和设置操作...'); 设置属性(); 设置状态(); 检查(); const roomCardList = document.querySelector('#room-card-list'); if (roomCardList) { observer.observe(roomCardList, config); console.log('已开始监听 #room-card-list 的变化...'); } else { console.error('#room-card-list 元素未找到!'); } }); } const currentHostname = window.location.hostname; const currentUrl = window.location.href; if ((currentHostname === 'www.bilibili.com' || currentHostname === 't.bilibili.com') && !currentUrl.startsWith("https://www.bilibili.com/correspond/")) { // 顶栏修改 console.log("主站", currentUrl); executeWithRetry('.header-entry-mini', () => { // 添加热门 const firstLi = document.querySelector('.left-entry > li:nth-child(2)'); if (firstLi) { const newLi = document.createElement('li'); newLi.className = 'v-popular-wrap'; newLi.innerHTML = '<a href="https://www.bilibili.com/v/popular/all/" target="_blank" class="default-entry"><span>热门</span></a>'; firstLi.parentNode.insertBefore(newLi, firstLi.nextSibling); console.log('已成功添加“热门”链接'); } else { console.error('未找到目标 <li> 元素!'); } // 直播首页 → 全部直播间页 const targetLink = document.querySelector('#biliMainHeader > div > div > ul.left-entry > li:nth-child(4) > a'); if (targetLink) { console.log('已成功修改“直播”链接'); targetLink.href = "https://live.bilibili.com/all"; } }, 1200); } })();