Greasy Fork is available in English.

Reddit Promotion Blocker

Blocks all of the promoted advertisements on Reddit.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Reddit Promotion Blocker
// @namespace    http://tampermonkey.net/
// @version      0.6.0
// @description  Blocks all of the promoted advertisements on Reddit.
// @author       Aiden Charles
// @match        http://reddit.com/*
// @match        https://reddit.com/*
// @match        http://www.reddit.com/*
// @match        https://www.reddit.com/*
// @match        http://old.reddit.com/*
// @match        https://old.reddit.com/*
// @grant        none
// ==/UserScript==

(function () {
    console.log("Reddit promotion blocker script is running!");

    function hide(selector, parentLevels = 0, text = "") {
        document.querySelectorAll(selector).forEach(element => {
            if (text === "" || element.textContent.includes(text)) {
                let target = element;
                for (let i = 0; i < parentLevels; i++) {
                    if (target.parentElement) {
                        target = target.parentElement;
                    } else {
                        return;
                    }
                }
                target.style.display = 'none';
            }
        });
    }

    const elementsToHide = {
        oldReddit: [
            ["span", 5, "promoted"],
            ["div .ad-container", 1],
            ["span .promoted-tag", 2]
        ],
        newReddit: [
            ["shreddit-ad-post"],
            ["shreddit-comments-page-ad"],
            ["shreddit-comment-tree-ad"],
            ["shreddit-async-loader[bundlename='sidebar_ad']"],
            ["shreddit-async-loader[bundlename='feed_announcement']"],
            ["div[data-before-content='advertisement']", 3],
            ["div .adsense-ad", 2],
            ["span .promoted-tag", 2],
            ["div .promotedlink"]
        ]
    };

    const observer = new MutationObserver(function () {
        const isOldReddit = window.location.hostname === "old.reddit.com";
        const targets = isOldReddit ? elementsToHide.oldReddit : elementsToHide.newReddit;
        targets.forEach(args => hide(...args));
    });

    observer.observe(document, {childList: true, subtree: true});
})();