remove-adds

remove adds

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name remove-adds
// @name:CN-zh_cn 移除广告
// @version 0.14
// @description remove adds
// @author gaojr
// @namespace https://github.com/gaojr/scripts-styles
// @license MIT
// @match https://*/*
// @require https://greasyfork.org/scripts/393085-commonsutil/code/CommonsUtil.js
// @grant none
// ==/UserScript==

const wlh = window.location.href;

// 目标[选择器|元素]
const targets = [];

/**
 * 移除目标
 */
const removeTargetAsSelector = () => {
  // 用英文逗号拼接选择器
  let selector = targets.join();
  if (!selector) {
    return;
  }
  removeAll(selector);
  // 清空列表
  targets.length = 0;
};

/**
 * 移除目标
 */
const removeTargetAsElement = () => {
  targets.forEach((ele) => {
    removeRecursively(ele);
  });
  // 清空列表
  targets.length = 0;
};

////////// 分割线

/**
 * 清楚iframe
 */
const cleanIframe = () => {
  const baidu = /https:\/\/pos\.baidu\.com\//;
  const google = /https:\/\/googleads/;

  _$$('iframe').forEach((ele) => {
    let src = ele.src;
    if (baidu.test(src) || google.test(src)) {
      targets.push(ele);
    }
  });
};

/**
 * 通用
 */
const deal = (list) => {
  list.forEach((e) => {
    _$$(e).forEach((ele) => {
      if (!ele.textContent.trim()) {
        targets.push(ele);
      }
    });
  });
  removeTargetAsElement();
}

/**
 * 通用-广告
 */
const dealCommons = () => {
  _$$('[data-google-query-id]').forEach((ele) => {
    targets.push(ele);
  });
  _$$('[aria-label]').forEach((ele) => {
    let label = ele.getAttribute('aria-label');
    if (/baidu-ad/.test(label)) {
      targets.push(ele);
    }
  });
};

/**
 * 通用-脚本
 */
const dealScripts = () => {
  // 干掉 body 里的脚本
  targets.push('body script');
  removeTargetAsSelector();
};

////////// 分割线

/**
 * CSDN
 */
const dealCsdn = () => {
  // 文章页面
  const article = /https:\/\/.*\.csdn\.net\/.*\/article\/details\/.*/;

  if (article.test(wlh)) {
    clickIt('.btn-readmore');
  }
};

/**
 * 异次元 iplaysoft.com
 */
const dealIplaysoft = () => {
  // 全局
  dealScripts();

  // 文章页面
  const article = /https:\/\/www\.iplaysoft\.com\/.+/;

  if (article.test(wlh)) {
    // 删掉有 style、无 id、无 class、无文字的 div
    _$$('div[style]:not([id]):not([class])').forEach((ele) => {
      if (!ele.textContent.trim()) {
        ele.remove();
      }
    });
  }
};

////////// 分割线

(function () {
  let func = () => {
    cleanIframe();
    dealCommons();
    removeTargetAsElement();

    const isCsdn = /https?:\/\/.*\.csdn\.net((\/.*)|(\/?))/;
    const isIplaysoft = /https?:\/\/www\.iplaysoft\.com((\/.*)|(\/?))/;
    const isWenku8 = /https?:\/\/www\.wenku8\.net\/novel((\/.*)|(\/?))/;

    if (isCsdn.test(wlh)) {
      dealCsdn();
    } else if (isIplaysoft.test(wlh)) {
      dealIplaysoft();
    } else if (isWenku8.test(wlh)) {
      deal(['div#adv900']);
    }
    removeTargetAsSelector();
  };
  addToFuncMap('resmove-add', func);
})();