Greasy Fork is available in English.

Ad-Block屏蔽指定网站广告(csdn等)

屏蔽csdn,w3school,runoob,iteye等网站广告

// ==UserScript==
// @name         Ad-Block屏蔽指定网站广告(csdn等)
// @description  屏蔽csdn,w3school,runoob,iteye等网站广告
// @namespace    ad_mask
// @version      2.4.4
// @author       vizo
// @require      https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @include      *://*csdn*
// @include      *://*runoob.com/*
// @include      *://*dytt8.net/*
// @include      *://*w3school.com.cn/*
// @include      *://*gitee.com/*
// @run-at       document-start
// @grant        GM_addStyle
// @grant        GM_getResourceText
// @grant        GM_setValue
// @grant        GM_getValue
// @noframes
// ==/UserScript==

let domainAry = [
  {
    name: 'csdn',
    ym: 'blog.csdn.net',
    strict: false,
  },
  {
    name: 'iteye',
    ym: 'iteye.com',
    strict: true,
  },
  {
    name: 'runoob',
    ym: 'runoob.com',
    strict: true,
  },
  {
    name: 'dytt',
    ym: 'dytt8.net',
    strict: true,
  },
  {
    name: 'w3school',
    ym: 'w3school.com.cn',
    strict: true,
  },
  {
    name: 'iconfont',
    ym: 'iconfont.cn',
    strict: true,
  },
  {
    name: 'gitee',
    ym: 'gitee.com',
    strict: true,
  },
]

GM_addStyle(`
  ._adb_csdn iframe,
  ._adb_csdn aside,
  ._adb_csdn #adContent,
  ._adb_csdn div[id^=layer],
  ._adb_csdn div[id*=dmp_ad],
  ._adb_csdn div[id*=kp_box],
  ._adb_csdn div[class*=course_target],
  ._adb_csdn div[class*=type_hot_word],
  ._adb_csdn .recommend-ad-box,
  ._adb_csdn .mediav_ad,
  ._adb_csdn .blog-expert-recommend-box,
  ._adb_csdn .recommend-fixed-box,
  ._adb_csdn .pulllog-box,
  ._adb_csdn .fourth_column,
  ._adb_csdn .login-mark,
  ._adb_csdn .ads,
  ._adb_csdn #passportbox,
  ._adb_csdn .tool-box,
  ._adb_csdn .blog-column-pay,
  ._adb_csdn #writeGuide,
  ._adb_csdn .csdn-side-toolbar,
  
  ._adb_dytt iframe,
  ._adb_dytt body>a,
  ._adb_dytt div[id^=cs_DIV],
  
  ._adb_iteye #layerd,
  ._adb_iconfont #pop_ad,
  
  ._adb_liaoxuefeng #x-sponsor-a,
  ._adb_liaoxuefeng #x-sponsor-b,
  
  ._adb_gitee body > .float-left-box,
  

  
  ._adb_w3school iframe
  
  {display:none !important;}
  
  ._adb_csdn #mainBox > main {
    transform: translateX(-10%);
  }
`)

let timer1s = 0

function throttle(func, wait) {
  let start = 0
  return function () {
    let now = Date.now()
    if (now - start >= wait) {
      func.apply(this, arguments)
      start = now
    }
  }
}

domainAry.forEach((v) => {
  let h = location.host
  let m = v.strict ? h === v.ym : h.includes(v.ym)
  if (m) {
    document.documentElement.classList.add('_adb_' + v.name)
    init()
  }
})

function timeout(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms))
}

function init() {
  let csdn = $('html').hasClass('_adb_csdn')
  clearTimeout(timer1s)
  let more = $('.btn-readmore')

  timer1s = setTimeout(() => {
    if (csdn) {
      if (more.length && more.is(':visible')) {
        more[0].click()
      }
    }

    $('html iframe').each(function () {
      $(this).remove()
    })
  }, 500)
}

$(function () {
  function del(ele) {
    $('html').find(ele).remove()
  }
  function empty(ele) {
    $('html').find(ele).parent().empty()
  }

  $(document).on('mousemove', throttle(function () {
      del('.csdn .recommend-ad-box')
      del('body > a')
      del('[id*=cscp]')
      init()
    }, 1000),
  )
})