百度结果广告过滤,垃圾信息过滤

2021/10/29 下午8:27:23

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        百度结果广告过滤,垃圾信息过滤 
// @namespace   Violentmonkey Scripts
// @match       *://www.baidu.com/*
// @grant       none
// @version     1.0
// @author      ZJS
// @description 2021/10/29 下午8:27:23
// ==/UserScript==
(function(){
  'use strict';
  console.log($)
  const url = location.href
  
  function action(){
    //过滤csdn搜索结果
    if(/\s?ie=/.test(url)){
      document.querySelectorAll('.c-container').forEach(item=>{
        //去掉搜索结果中的视频内容
        const title= item.querySelector('h3')?.textContent
        if(item.querySelector('.video-main-title_S_LlQ')){
          return item.remove()
        }
        //去掉百度的推广内容
        if(item.querySelector('.ec-tuiguang')){
          console.log(title,'remove')
          return item.remove()
        }
        //搜索内容的关键词过滤 
        const filter= /提供|来自互联网|免费小说|相关推荐/
        if(filter.test(item.querySelector('.c-abstract')?.textContent)){
          console.log(title,'remove')
          item.remove()
        }
      })
    }    
  }
  setInterval(()=>{
    action()
  },500)
})()