DIY AdBlock for Der Standard

A basic AdBlocker for Der Standard with Tampermonkey

A picture of the author, Jakob Maier
Jakob Maier
Nov 25, 2021

The website of the austrian newspaper Der Standard does not allow the use of an AdBlock browser extension. But there is an easy workaround: just write your own AdBlock. As it turns out, it's quite easy when you use a Userscript manager like Tampermonkey. And while this script is quite basic, it works quite well and hides virtually all ads on the website.

This script just looks for certain elements that are known to be ads and then hides them. Because not all ad elements are rendered when the page is first loaded, I added a MutationObserver to watch for changes to the DOM. I realize that this looks at the entire page every time something changes, which is not really efficient, so this may be changed in the future.

This is the script I use:

// ==UserScript==
// @name         Der Standard AdBlock
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Easy way to block ads on derstandard.com
// @author       Jakob Maier
// @match        https://www.derstandard.at/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
	"use strict";

	const selectors = [
		"ad-container",
		".native-ad",
		".animation",
		".teads-ui",
		".template.theme-supporter",
		".dstpiano-message.dstpiano-width-960.template-loaded",
		".dstpiano-container.visible-message",
		"#piano-supporter-inline-container",
	];

	const callback = (mutations, observer) => {
		for (let selector of selectors) {
			for (let element of document.querySelectorAll(selector)) {
				element.style.display = "none";
			}
		}
	};

	let observer = new MutationObserver(callback);
	let body = document.querySelector("body");
	observer.observe(body, { childList: true, subtree: true });
})();

↑ back to top

© 2023 Jakob Maier
kontakt & impressum
edit