编写油猴脚本绕过 saltyleo 的广告屏蔽检测


编写油猴脚本绕过 saltyleo 的广告屏蔽检测

在 saltyleo 这个网站中如果有 ADGuard 之类的屏蔽广告的插件,就会强弹弹窗,无法正常使用。必须关闭插件才能正常使用。那自然不能忍,分析了一波网页代码,写了个油猴脚本,直接把这段检测逻辑屏蔽了。

通过分析网页可得知,执行强制弹窗等行为的方法是 showDetectionSummary,所以只要把这个方法不让他执行即可。

思路就是劫持 setTimeout 方法,当执行 showDetectionSummary 方法的时候跳过。

脚本如下:

// ==UserScript==
// @name         saltyleo的书架反广告屏蔽检测
// @namespace    http://tampermonkey.net/
// @version      2026-02-03
// @description  try to take over the world!
// @author       You
// @match        https://tstrs.me/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
  'use strict';

  const rawSetTimeout = window.setTimeout;

  window.setTimeout = function (fn, delay, ...args) {
    // 命中 setTimeout(showDetectionSummary, 100)
    if (
      delay === 100 &&
      typeof fn === 'function' &&
      fn.name === 'showDetectionSummary'
    ) {
      console.log('[Tampermonkey] 拦截 showDetectionSummary');
      // 方案 A:直接不执行
      return 0;

      // 方案 B:改成 9999999
      // return rawSetTimeout(fn, 9999999, ...args);
    }

    return rawSetTimeout(fn, delay, ...args);
  };
})();

文章作者: 草莓多多
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 草莓多多 !
  目录