// ==UserScript== // @name B站自动不感兴趣 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 自动隐藏B站首页含屏蔽词视频 // @author 想和李恒道击剑 // @match https://www.bilibili.com/ // @grant none // ==/UserScript== (function () { 'use strict'; // 屏蔽词列表 const blockKeywords = ['联盟', 'lol', 'LOL']; // 屏蔽类型:true = "UP主不感兴趣",false = "话题不感兴趣" const blockUp = true; // 检查标题是否包含屏蔽词 function matchesBlockedKeywords(title) { return blockKeywords.some(keyword => title.includes(keyword)); } // 模拟鼠标悬停事件 function simulateHover(element) { if (element) { const mouseEnterEvent = new MouseEvent('mouseenter', { bubbles: true, cancelable: true, view: window }); element.dispatchEvent(mouseEnterEvent); } } // 点击按钮的通用函数 function simulateClick(element) { if (element) { const event = new MouseEvent('click', { bubbles: true, cancelable: true, view: window }); element.dispatchEvent(event); } } // 监听全局菜单的动态生成 function observeGlobalMenu() { const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { const popover = document.querySelector('.vui_popover-content'); if (popover) { const options = Array.from(popover.querySelectorAll('.bili-video-card__info--no-interest-panel--item')); const targetOption = blockUp ? options.find(option => option.innerText.includes('不想看此UP主')) : options.find(option => option.innerText.includes('内容不感兴趣')); if (targetOption) { simulateClick(targetOption); console.log('操作完成:屏蔽成功'); } } }); }); // 监听 body 的子节点变化(全局菜单可能会在 body 下生成) observer.observe(document.body, { childList: true, subtree: true }); } // 扫描视频并触发操作 function scanAndBlock() { const videos = document.querySelectorAll('.bili-video-card'); videos.forEach(video => { const titleElement = video.querySelector('.bili-video-card__info--tit'); const noInterestButton = video.querySelector('.bili-video-card__info--no-interest'); if (titleElement && noInterestButton) { const title = titleElement.innerText; if (matchesBlockedKeywords(title)) { console.log('发现屏蔽视频:', title); simulateHover(noInterestButton); // 鼠标悬停触发菜单 } } }); } // 启动全局菜单监听 observeGlobalMenu(); // 定时扫描(适应动态加载内容) setInterval(scanAndBlock, 3000); // 每3秒检查一次 })();