您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
隐藏百度贴吧广告
// ==UserScript== // @name tieba // @namespace http://tampermonkey.net/ // @version 2025-05-07 // @description 隐藏百度贴吧广告 // @author You // @match https://tieba.baidu.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=microsoft.com // @grant GM_log // @license MIT // ==/UserScript== (function() { 'use strict'; GM_log("Init tieba"); // 目标类名 let targetClassNames = ['custom-custom-ad-container','ylh-ad-container']; // 隐藏广告函数 function hideAdContainers() { targetClassNames.forEach(v=>{ const adContainers = document.getElementsByClassName(v); for (let container of adContainers) { container.style.display = 'none'; console.log('已隐藏广告容器:', container); } if (adContainers.length > 0) { console.log(`隐藏了 ${adContainers.length} 个广告容器`); } }) } // 初始执行 hideAdContainers(); // 使用MutationObserver监听DOM变化 const observer = new MutationObserver(function(mutations) { hideAdContainers(); }); // 开始观察DOM变化 observer.observe(document.body, { childList: true, subtree: true }); // 监听history变化(应对SPA页面导航) let pushState = history.pushState; history.pushState = function() { pushState.apply(history, arguments); setTimeout(hideAdContainers, 100); }; let replaceState = history.replaceState; history.replaceState = function() { replaceState.apply(history, arguments); setTimeout(hideAdContainers, 100); }; window.addEventListener('popstate', function() { setTimeout(hideAdContainers, 100); }); })();