say goodbye to CSDN

清除搜索结果中指向 CSDN 网站的条目

Stan na 17-12-2020. Zobacz najnowsza wersja.

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         say goodbye to CSDN
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  清除搜索结果中指向 CSDN 网站的条目
// @author       zoffy zhang
// @run-at       document-idle
// @include      https://*.google.com/*
// @include      https://*.baidu.com/*
// @include      https://*.bing.com/*
// @grant        none
// ==/UserScript==

// 参数配置
var configs = {
  'google.com': ['#rso', '.g', 'cite', /csdn\.net/],
  'bing.com': ['#b_results', '.b_algo', 'cite', /csdn\.net/],
  'baidu.com': ['#content_left', '.result', 'a.c-showurl', /csdn/i]
}

function removeDom(parentSel, childrenSel, targetSel, regexp) {
  var parent = document.querySelector(parentSel)
  var children = parent.querySelectorAll(childrenSel)
  for (let i = children.length - 1, len = children.length; i >= 0; i--) {
    var text = children[i].querySelector(targetSel).innerText
    if (regexp.test(text)) {
      parent.removeChild(children[i])
    }
  }
}

;(function() {
  'use strict'
  var origin = window.location.origin
  var keys = Object.keys(configs)
  var theKey = keys.find(function(key) {
    return origin.match(key)
  })
  var params = configs[theKey]
  removeDom.apply(null, params)
})()