tonybai.com 去广告

tonybai.com去广告

目前為 2024-08-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        tonybai.com 去广告
// @namespace   Violentmonkey Scripts
// @match       https://tonybai.com/*
// @grant       none
// @version     1.0
// @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());