adam4adam remove ads

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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