Reddit NSFW Bypass

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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
    });

})();