修复阮一峰博客广告拦截器问题

修复阮一峰博客中广告拦截器导致的显示问题,并提供解决方案以移除提示信息。

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         修复阮一峰博客广告拦截器问题
// @version      0.6.2
// @description  修复阮一峰博客中广告拦截器导致的显示问题,并提供解决方案以移除提示信息。
// @author       kj863257
// @match        *://*.ruanyifeng.com/*
// @grant        none
// @run-at       document-start
// @namespace    https://greasyfork.org/users/168722
// @supportURL   https://greasyfork.org/zh-CN/scripts/432380
// ==/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;
}

// 移除检测脚本
document.querySelector('script[src*=checker]')?.remove();

// 保存原始的setTimeout函数
window._setTimeout = window.setTimeout;

// 重写setTimeout,过滤掉checker函数
var fun = (f, t) => {
  if (f.name !== 'checker') {
    window._setTimeout(f, t);
  }
};
window.setTimeout = fun;

// 克隆主内容元素
var content = document.querySelector('#main-content').cloneNode(true);

// 加载CSS文件
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 = '<img src="https://wangbase.com/blogimg/asset/202107/bg2021072117.png" alt="" style="border: 0pt none;">';
}, 200);

setTimeout(ruanyifeng, 800);
loadjscssfile('/static/themes/theme_scrapbook/theme_scrapbook.css');