Greasy Fork

Greasy Fork is available in English.

uBlock Ad Bypass

A simple script to bypass ad AD detection

当前为 2025-02-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name            uBlock Ad Bypass
//
// @version         1.0.0
// @description     A simple script to bypass ad AD detection
// @match           *://*/*
// @run-at          document-start
// @grant           none
// @license MIT
// @namespace http://greasyfork.icu/users/1440075
// ==/UserScript==

// 获取原始的 getComputedStyle 函数
const originalGetComputedStyle = window.getComputedStyle;

Object.defineProperty(window, "getComputedStyle", {
  get() {
    return (element) => {
      // 判断元素是否为可能的广告类型
      if (
        element instanceof HTMLImageElement || // 图片
        element instanceof HTMLIFrameElement || // iframe
        element instanceof HTMLScriptElement || // 脚本
        element instanceof HTMLDivElement || // div 元素,通常用于广告容器
        element instanceof HTMLSpanElement // span 元素,某些广告可能使用 span
      ) {
        // 通过元素的属性判断是否是广告
        const isAd = (
          (element.src && (element.src.includes('ad') || element.src.includes('banner') || element.src.includes('ads'))) ||
          (element.id && element.id.includes('ad')) ||
          (element.className && element.className.includes('ad')) ||
          (element.style && element.style.display === 'none')
        );

        // 如果判断为广告,强制其显示
        if (isAd) {
          return {
            ...originalGetComputedStyle(element),
            display: "block"
          };
        }
      }
      // 返回原始样式,非广告元素
      return originalGetComputedStyle(element);
    };
  }
});