阮一峰adblock检测绕过

浏览器开启了adblock,使用插件之前访问阮一峰网页

 

 

 解决方案:

1.在浏览器安装Tampermonkey插件

 

2.插件中添加脚本

// ==UserScript==
// @name            ruanyifeng adblock helper
// @namespace       https://github.com/xcr1234
// @version         1.0.0
// @description     test
// @match         *://www.ruanyifeng.com/*
// @match         *://ruanyifeng.com/*
// @run-at          document-start
// @grant           none
// ==/UserScript==
const t = window.getComputedStyle;
Object.defineProperty(window, "getComputedStyle", {
  get() {
    return (e) => e instanceof HTMLImageElement && e.src.includes("wangbase.com/blogimg/asset") ? {
      ...t(e),
      display: "block"
    } : t(e);
  }
});

 

 

编译上述脚本用到的源码如下

const originFn = window.getComputedStyle


Object.defineProperty(window, 'getComputedStyle', {
    get(){
        return (el: any) =>{
            if(el instanceof HTMLImageElement && el.src.includes('wangbase.com/blogimg/asset')){
                return {
                    ...originFn(el),
                    display: 'block'
                }
            }
            return originFn(el)
        }
    }
})

 

posted @ 2024-07-23 12:36     阅读(206)  评论(0)    收藏  举报