adam4adam remove ads

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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!");