Greasy Fork

Greasy Fork is available in English.

say goodbye to CSDN

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

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