Reddit NSFW Bypass

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

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

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

})();