Reddit NSFW Bypass

Watches for reddit NSFW login prompt, then deletes it and reveals contents.

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 NSFW Bypass
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Watches for reddit NSFW login prompt, then deletes it and reveals contents.
// @author       You
// @match        https://www.reddit.com/r/*
// @icon         https://www.reddit.com/favicon.ico
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

	function doRemove(){

        const element = document.getElementById("blocking-modal-contents");
        if (element !== null) {
            element.remove();
            console.log(`[ElementRemover] 'blocking-modal-contents' removed.`);
        }

		document.querySelectorAll("svg[icon-name='nsfw-fill']").forEach(svgImage => {
			let targetParent = svgImage.parentNode.parentNode.parentNode;
			if (targetParent) {
				let imageElement = targetParent.querySelector("img");
				if (imageElement && imageElement.style && imageElement.style.filter.includes("blur")) {
					imageElement.style.filter = imageElement.style.filter.replace(/blur\(\d+px\)/g, '');
					svgImage.parentNode.parentNode.remove();
					console.log(`[ElementRemover] NSFW image revealed.`);
				}
			}
		});

		function revealNsfwContent(container) {
			revealTextContent(container);
			revealThumbnailContent(container);
		}

		function revealThumbnailContent(container) {
			const blurredBody = container.querySelector("div[slot='post-media-container']");
			if (!blurredBody) return;

			const revealedDiv = container.querySelector("div[slot='revealed']");
			if (!revealedDiv) return;
			if (revealedDiv.parentNode == blurredBody) return;

			blurredBody.insertBefore(revealedDiv, blurredBody.firstChild);

			for (let i = blurredBody.children.length - 1; i >= 1; i--) {
				blurredBody.removeChild(blurredBody.children[i]);
			}

			console.log(`[ElementRemover] NSFW thumbnail revealed. ${blurredBody.children.length} children remain.`);
		}

		function revealTextContent(container) {
			const textBody = container.querySelector("shreddit-post-text-body");
			if (!textBody) return;

			const contentZone = textBody.querySelector("div");
			if (!contentZone) return;

			textBody.querySelectorAll("div[slot='revealed']").forEach(div => {
				const contentElement = div.querySelector("div[property='schema:articleBody']");
				if (!contentElement) return;

				contentZone.insertBefore(contentElement, contentZone.firstChild);
				console.log(`[ElementRemover] NSFW content revealed.`);

				while (contentZone.children.length > 1) {
					contentZone.removeChild(contentZone.lastChild);
				}
			});
		}

		document.querySelectorAll("shreddit-post").forEach(article => revealNsfwContent(article));
    }


    const observer = new MutationObserver((_,__) => { doRemove(); });

    doRemove(null);

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

})();