removes annoying ads from adam4adam*.com sites, tested in MS Edge and Firefox
// ==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!");