adam4adam remove ads

removes annoying ads from adam4adam*.com sites, tested in MS Edge and Firefox

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name        adam4adam remove ads
// @namespace   Violentmonkey Scripts
// @icon
// @version     0.1.2
// @license     MIT
//
// @match       http*://*.adam4adam*.com/*
// @grant       none
//
// @author      [email protected]
// @description removes annoying ads from adam4adam*.com sites, tested in MS Edge and Firefox
// ==/UserScript==

/* jshint esversion: 8 */

// each line is a regex anchored to start of class name via '^'
// and to the end of class name via $
var classRegexTargetSelfStr = `
promo-bar-ads
(banner-)?vip.*
ads-.+
header-banner
mys-wrapper
adsbygoogle.*
stories-feed-container
`;

// special case:  easier to identify the child of an elt we need
// to remove than the elt itself
var classRegexTargetParentStr = `
sticky-block
`;

const LOG_TAG = "a4a de-ad-ifier :: ";
var iframesRemoved = false;



function constructRegex(multilineStr) {
  return new RegExp("^(" + multilineStr.split(`\n`)
                                       .join(`|`)
                                       .replace(/^\|/, ``)
                                       .replace(/\|$/, ``) +
                                       ")$");
}
const classRegexTargetSelf = constructRegex(classRegexTargetSelfStr);
const classRegexTargetParent = constructRegex(classRegexTargetParentStr)


function removeByClassRegex(classRegex, removeParent) {
  var pendingRemoval = [];
  Array.from(document.querySelectorAll('*')).forEach(e => {
    if(classRegex.test(e.className)) {
        pendingRemoval.push(e);
    }
  });

  pendingRemoval.forEach(e => {
    console.log(LOG_TAG + "removing element with class='" + e.className + "'");
    try {
      if (removeParent) {
        e.parentNode.remove();
      } else {
        e.remove();
      }
    } catch(error) {
      console.log(LOG_TAG + "Error encountered:  " + error);
    }
  });

  return pendingRemoval.length;
}


var totalItn = 0;

const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));

async function runWithPostDelay(itn, ms) {
  for(var i = 0; i < itn; i++) {
    totalItn++;
    console.log(LOG_TAG + "run #" + totalItn + ":  a4a removing ad-related elements");

    var removedCount = 0;
    removedCount += removeByClassRegex(classRegexTargetParent, true);
    removedCount += removeByClassRegex(classRegexTargetSelf, false);

    if(! iframesRemoved) {
      var numIframesRemoved = 0;
      Array.from(document.getElementsByTagName("iframe")).map(e => {
        iframesRemoved = true;
        e.remove();
      });
    }
    console.log(LOG_TAG + "sleeping for " + (ms/1000) + "sec before running again");
    await wait(ms);
  }
}

// run up to 4 times, each iteration waiting 1.5s before next iteration (or exiting)
runWithPostDelay(4,1500);

// run up to 4 additional times, each iteration waiting 3s before next iteration (or exiting)
runWithPostDelay(4,3000);

console.log(LOG_TAG + "finished!");