Greasy Fork

Greasy Fork is available in English.

6v去广告

去除6v bt之家 阿里云盘广告

目前为 2023-05-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         6v去广告
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  去除6v bt之家 阿里云盘广告
// @author       gepik
// @match        *://www.hao6v.cc/*
// @match        https://www.hao6v.tv/*
// @match        https://www.btbtt15.com/*
// @match        https://www.aliyundrive.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hao6v.cc
// @require http://code.jquery.com/jquery-2.1.1.min.js
// @grant        none
// @license      AGPL License
// ==/UserScript==

(function() {
  const $ = window.$;
  'use strict';
  let idList = ['HMcoupletDivleft','HMcoupletDivright','wrapper_left_bg llll','wrapper_right_bg','HMRichBox','ccc123']
  let classList = ['width imgs_1','wrapper_bg_c','share-list-banner--1E8Jr']

  function findADDom(){
      let adDomList = idList.map(id=>$('#'+id)).concat(classList.map(classList=>$('.'+classList.split(' ').join('.'))))
      adDomList = adDomList.filter(it=>it.length);
      return adDomList;
  }
  function removeAd() {
      let adDomList = findADDom();
      adDomList.forEach(it=>it.hide());
  }
  $(document).ready(removeAd)

  // 通过className获取目标元素
  function filterTargetDomByClassName(dom) {
      const domClassName = Array.from(dom.classList).join(' ');
      if(classList.includes(domClassName)) return dom;
      return null;

  }
  // 对目标元素进行隐藏
  function hideTargetDom(dom) {
      const hitDom =filterTargetDomByClassName(dom);
      if(hitDom) hitDom.hide();
  }
  // 广告的观察器
  function getAdObserver() {
      if (!window._adObserver) {
          const observer = new MutationObserver(mutations => {
              for (const mutation of mutations) {
                  if(mutation.addedNodes) {
                      for(let dom of mutation.addedNodes) {
                          if(idList.includes(dom.id)) {
                              $(dom).hide()
                          }
                          hideTargetDom(dom);
                      }
                  }
                  hideTargetDom(mutation.target);
              }
          })

          observer.start = function() {
              if (!this._active) {
                  this.observe(document.body, { childList: true,subtree:true });
                  this._active = true;
              }
          }
          observer.end = function() {
              if (this._active) {
                  this.disconnect();
              }
          }

          // window.addEventListener('urlchange', function() {
          //     observer[location.href.indexOf('/answer/') === -1 ? 'start' : 'end']();
          // })
          window._adObserver = observer;
      }
      return window._adObserver
  }
  const observer = getAdObserver()
  observer.start()
  if(location.host.includes('6v')) {
      window.sessionStorage.setItem('fbox', '1')
  }
})();