// ==UserScript== // @name 阮一峰博客广告不显示后的问题修复处理 // @version 0.5 // @description 对阮一峰博客提示的‘您使用了广告拦截器,导致本站内容无法显示。请将 www.ruanyifeng.com 加入白名单,解除广告屏蔽后,刷新页面,谢谢。’信息进行修复。 // @author // @match *://*.ruanyifeng.com/* // @grant none // @run-at document-start // @namespace https://greasyfork.org/users/168722 // @downloadURL none // ==/UserScript== // 保存原始的getComputedStyle函数 var originalGetComputedStyle = window.getComputedStyle; // 重写getComputedStyle window.getComputedStyle = function(element) { // 调用原始的getComputedStyle获取样式对象 var style = originalGetComputedStyle.apply(this, arguments); // 创建代理对象 var styleProxy = new Proxy(style, { get: function(target, prop) { // 判断是否获取.display属性 if (prop === 'display') { // 在这里可以添加自定义逻辑,例如判断元素类型并返回计算结果 if (element.tagName.toLowerCase() === 'img') { // 对于img元素,返回计算后的display值 return calculateDisplayForImg(element); } else if (element.parentElement) { // 对于父元素,返回计算后的display值 return calculateDisplayForParent(element.parentElement); } } // 对于其他属性,返回原始样式对象中的值 return target[prop]; } }); return styleProxy; }; // 自定义逻辑:计算img元素的display值 function calculateDisplayForImg(imgElement) { if(imgElement.src.indexOf('wangbase.com')==-1){ return imgElement.display; } return 'inline'; } // 自定义逻辑:计算父元素的display值 function calculateDisplayForParent(parentElement) { if(parentElement.parentElement.id==='feed_icon'){ return 'inline'; } return parentElement.display; } var parentElement = img.parentElement; console.log(window.getComputedStyle(parentElement).display); document.querySelector('script[src*=checker]')?.remove(); window._setTimeout = window.setTimeout; var fun = (f,t)=>{ if(f.name !== 'checker'){ window._setTimeout(f, t); } }; window.setTimeout = fun; var content = document.querySelector('#main-content').cloneNode(true); function loadjscssfile(filename) { var fileref = document.createElement("link"); fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", filename); if (typeof fileref != "undefined") document.getElementsByTagName("head")[0].appendChild(fileref) } function ruanyifeng() { document.getElementsByClassName('asset-meta')[0].nextElementSibling.style = 'display:none'; document.querySelector('article.hentry').insertBefore(content, document.querySelector('.asset-footer')); } setTimeout(()=>{ var feedIconLink = document.querySelector('#feed_icon > a'); feedIconLink.innerHTML = ''; }, 200); setTimeout(ruanyifeng, 800); loadjscssfile('/static/themes/theme_scrapbook/theme_scrapbook.css');