tonybai.com 去广告

tonybai.com去广告

当前为 2024-08-23 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        tonybai.com 去广告
// @namespace   Violentmonkey Scripts
// @match       https://tonybai.com/*
// @grant       none
// @version     1.1
// @author      ddatsh
// @description tonybai.com去广告
// ==/UserScript==

const hrTags = document.querySelectorAll('hr[isinvalidtag="true"]');
const articleTags = document.querySelectorAll('article');

// 存储所有需要删除的 <p> 标签
const pTagsToRemove = [];

// 遍历每个 <hr> 标签
hrTags.forEach(hr => {
  // 找到最近的 <article> 标签
  let closestArticle = null;
  articleTags.forEach(article => {
    if (!closestArticle || hr.compareDocumentPosition(article) & Node.DOCUMENT_POSITION_FOLLOWING) {
      closestArticle = article;
    }
  });

  // 如果找到了 <hr> 和 <article> 标签,收集需要删除的 <p> 标签
  if (closestArticle) {
    // 从 <hr> 到 <article> 之间的所有节点
    let current = hr.nextElementSibling;
    while (current && current !== closestArticle) {

        pTagsToRemove.push(current);

      current = current.nextElementSibling;
    }
  }
  hr.remove();
});

// 删除所有收集到的 <p> 标签
pTagsToRemove.forEach(p => p.remove());


// 获取包含section元素的父容器
var parentDiv = document.getElementById('secondary');
parentDiv.style.paddingTop = '0';

var firstWidgetSection = parentDiv.querySelector('section.widget');

// 如果找到该元素,从DOM中移除
if (firstWidgetSection) {
  firstWidgetSection.parentNode.removeChild(firstWidgetSection);
}

// 单独查找并移除具有特定ID的section元素
var sectionText4 = document.getElementById('text-4');
if (sectionText4) {
  sectionText4.parentNode.removeChild(sectionText4);
}

var sectionText3 = document.getElementById('text-3');
if (sectionText3) {
  sectionText3.parentNode.removeChild(sectionText3);
}
var wpm_subscribe_widget = document.getElementById('wpm_subscribe_widget-3');
if (sectionText3) {
  wpm_subscribe_widget.parentNode.removeChild(wpm_subscribe_widget);
}