您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
2025-3-25更新
// ==UserScript== // @description 2025-3-25更新 // @name B站广告精准屏蔽(修复版) // @match https://www.bilibili.com/* // @grant GM_addStyle // @version 0.0.1.20250325141130 // @namespace https://greasyfork.org/users/398195 // ==/UserScript== (function() { 'use strict'; const config = { // 更精准的广告路径匹配 adHrefPattern: /^(https:\/\/cm\.bilibili\.com\/cm\/api\/fees\/pc\/)/, // 广告父容器特征 parentSelectors: [ 'div.bili-video-card', 'div[data-ad-unit]', 'section[data-feeds-ad]' ], debug: true }; function log(...args) { if(config.debug) console.log('[广告调试]', ...args); } // 修正版安全检测 function isUnsafeContainer(container) { if (!container) return false; // 特征1:包含广告属性 const hasAdAttr = container.hasAttribute('data-ad') || container.querySelector('[data-ad-mark]'); // 特征2:存在广告类名 const hasAdClass = Array.from(container.classList).some(c => c.includes('ad') || c.includes('commercial')); // 特征3:尺寸符合广告特征 const isAdSize = container.offsetWidth > 280 && container.offsetWidth < 680; return hasAdAttr || hasAdClass || isAdSize; } function preciseBlock() { document.querySelectorAll('a').forEach(a => { try { // 严格匹配逻辑 if (!config.adHrefPattern.test(a.href)) return; const container = a.closest(config.parentSelectors.join(',')); if (!container || container.dataset.processed) return; // 关键逻辑修正!!! if (isUnsafeContainer(container)) { container.style.display = 'none'; container.dataset.processed = true; log('成功屏蔽:', container); } else { log('安全容器(未屏蔽):', container); } } catch (error) { log('处理异常:', error); } }); } // 观察者配置保持不变 const observer = new MutationObserver(() => preciseBlock()); observer.observe(document, { subtree: true, childList: true }); // 初始化 preciseBlock(); setInterval(preciseBlock, 1500); })();