// ==UserScript== // @name 哔哩哔哩增强工具箱 // @author 平凡的世界 // @description 优化B站界面并自动点击"最常访问" // @version 1.0.0 // @match https://www.bilibili.com/* // @match https://space.bilibili.com/* // @grant GM_addStyle // @run-at document-end // ==/UserScript== (function() { 'use strict'; // ===== 样式优化模块 ===== const styleOptimization = () => { // 隐藏广告、活动、直播等内容 const style = ` #notice, #slide_ad, .btn-ad, .img-ad, .ad-report, .adblock-tips, .adcard, .b-footer-wrap > .split-line, .other-link, .footer-icons, .international-footer, .recommended-swipe, .act-end, .act-now, .eva-banner, .bpx-player-error-sign, .bpx-player-toast-wrap, .container > .bili-video-card:not(.enable-no-interest), .container > .feed-card, .container > .floor-single-card, .container > .grid-anchor, .download-entry, .feed-roll-btn, .flexible-roll-btn-inner > .btn-text, .left-entry > .v-popover-wrap:not(:has(>a)), .vip-entry-containter, .vip-wrap, .video-ai-assistant-badge, .video-page-game-card-small, .video-tool-more, [class^=bili-live-card], [class^=paybar_container], div.bili-feed-card:has(>div[class^=bili-live-card]), [class^=areaLimitPop_content] { display: none !important; } /* 稍微优化一下布局 */ .home-zone { margin-top: 20px !important; } .bili-video-card { transition: all 0.3s ease !important; } .bili-video-card:hover { transform: translateY(-5px) !important; } `; // 应用样式 GM_addStyle(style); }; // ===== 智能点击模块 ===== const smartClicker = () => { const CONFIG = { TARGET_TEXT: "最常访问", // 目标按钮文字 CHECK_INTERVAL: 500, // 基础检查间隔 MAX_WAIT_TIME: 10000, // 最大等待时间(ms) OBSERVE_DEEP: true // 深度DOM监听 }; class ClickController { constructor() { this.observer = null; this.timer = null; this.isRunning = false; this.init(); } // 初始化监控 init() { this.setupRouterListener(); this.setupDOMObserver(); this.startCheckCycle(); } // 路由变化监听 setupRouterListener() { let lastUrl = location.href; setInterval(() => { if (location.href !== lastUrl) { lastUrl = location.href; this.onRouteChange(); } }, 1000); } setupDOMObserver() { this.observer = new MutationObserver(mutations => { if (this.isTargetPage()) this.attemptClick(); }); this.observer.observe(document, { childList: true, subtree: CONFIG.OBSERVE_DEEP }); } startCheckCycle() { this.timer = setInterval(() => { if (this.isTargetPage()) this.attemptClick(); }, CONFIG.CHECK_INTERVAL); } attemptClick() { if (this.isRunning) return; const btn = this.findTargetButton(); if (btn) { this.isRunning = true; console.log('触发智能点击'); btn.click(); setTimeout(() => this.isRunning = false, 1000); } } findTargetButton() { return [...document.querySelectorAll('.be-radio, .radio-filter__item')] .find(btn => btn.textContent.includes(CONFIG.TARGET_TEXT)); } onRouteChange() { if (this.isTargetPage()) { this.attemptClick(); this.resetObserver(); } } isTargetPage() { return /\/relation\/follow|\/fans\/follow/.test(location.pathname); } resetObserver() { this.observer.disconnect(); this.setupDOMObserver(); } } new ClickController(); }; styleOptimization(); smartClicker(); })();