Reddit Promotion Blocker

Blocks all of the promoted advertisements on Reddit.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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});
})();