Reddit Bypass Enhancer

Bypass the "open in app prompt", unblur NSFW content and thumbnails, remove the blur from community highlight cards.

当前为 2025-01-22 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Reddit Bypass Enhancer
// @version      1.9
// @description  Bypass the "open in app prompt", unblur NSFW content and thumbnails, remove the blur from community highlight cards.
// @author       UniverseDev
// @license      GPL-3.0-or-later
// @match        https://www.reddit.com/*
// @match        https://sh.reddit.com/*
// @grant        none
// @run-at       document-start
// @noframes
// @namespace https://greasyfork.org/en/users/1030895-universedev
// ==/UserScript==
'use strict';

(function () {
    function queryElementsDeep(selector) {
        const foundElements = new Set();
        try {
            const lightDomElements = document.querySelectorAll(selector);
            lightDomElements.forEach(el => foundElements.add(el));
            const allElements = document.querySelectorAll('*');
            for (const el of allElements) {
                if (el.shadowRoot) {
                    const shadowElements = el.shadowRoot.querySelectorAll(selector);
                    shadowElements.forEach(el => foundElements.add(el));
                }
            }
        } catch (error) {
            console.error("Error in queryElementsDeep:", error);
        }
        return Array.from(foundElements);
    }

    const SELECTORS = {
        nsfwModal: `${'shreddit-async-loader'}[${'bundlename'}*="nsfw_blocking_modal"]`,
        promptContainer: `${'xpromo-nsfw-blocking-container'} > *`,
        prompt: '.prompt',
        blurredContainer: 'shreddit-blurred-container',
        thumbnailBlur: '.thumbnail-blur',
        communityHighlightCard: 'community-highlight-card',
        thumbnailImage: 'img.mb-0.h-full.w-full.object-cover',
        thumbnailShadow: '.thumbnail-shadow',
        mediaBackground: '.bg-media-background',
        blurredSpan: 'span.inner.blurred',
        scrim: '.absolute.top-0.left-0.w-full.h-full.bg-scrim',
        imageFilter: 'img.mb-0.h-full.w-full.object-cover',
        video: 'shreddit-player, video',
        mediaTelemetryObserver: 'media-telemetry-observer',
        mediaPlayerLoader: 'shreddit-async-loader[bundlename="media_player_loader"]',
        shredditPlayer: 'shreddit-player',
        outerContainer: 'div.outer.h-full',
        badgeContainer: '.flex.items-center.gap-2xs.text-white'

    };

    const BLURRED_TAG = SELECTORS.blurredContainer;
    const MEDIA_TELEMETRY_OBSERVER_SELECTOR = SELECTORS.mediaTelemetryObserver;
    const BADGE_CONTAINER = SELECTORS.badgeContainer;

    function removeNSFWBlock() {
      try {
        const nsfwModal = document.querySelector(SELECTORS.nsfwModal);
        if (nsfwModal) {
            nsfwModal.remove();
        }

        const promptContainer = document.querySelector(SELECTORS.promptContainer);
        let prompt = null;
        if (promptContainer && promptContainer.shadowRoot) {
            prompt = promptContainer.shadowRoot.querySelector(SELECTORS.prompt);
        }
        if (prompt) {
            prompt.remove();
        }

        const blurredContainers = document.querySelectorAll(BLURRED_TAG);
        blurredContainers.forEach(container => {
          try {
             if (container.shadowRoot?.innerHTML && container.firstElementChild) {
                container.firstElementChild.addEventListener('click', function(e) {
                  e.preventDefault();
                    if (e.target.closest(MEDIA_TELEMETRY_OBSERVER_SELECTOR)) {
                      e.stopPropagation();
                    }
                    e.target.click();
                }, { once: true });
                 container.firstElementChild.click();
            }
          } catch (error) {
                console.error("Error processing blurred container:", error, container);
            }
        });

        document.querySelectorAll(SELECTORS.thumbnailBlur).forEach(el => el.classList.remove('thumbnail-blur'));
        document.querySelectorAll(SELECTORS.communityHighlightCard).forEach(card => card.removeAttribute('blurred'));

        document.querySelectorAll(SELECTORS.imageFilter).forEach(img => img.style.removeProperty('filter'));
        document.querySelectorAll(SELECTORS.video).forEach(video => {
            video.style.filter = '';
            video.classList.remove('blur');
        });

        const thumbnailShadow = document.querySelector(SELECTORS.thumbnailShadow);
        if (thumbnailShadow) {
            thumbnailShadow.remove();
        }

        const mediaBackground = document.querySelector(SELECTORS.mediaBackground);
        if (mediaBackground) {
            mediaBackground.style.backgroundColor = 'transparent';
        }

        queryElementsDeep(SELECTORS.blurredSpan).forEach(span => {
            span.style.filter = '';
        });
        queryElementsDeep(SELECTORS.scrim).forEach(scrim => {
            scrim.remove();
        });
        queryElementsDeep(BADGE_CONTAINER).forEach(badge => {
          badge.remove();
        });
      }
       catch (error) {
            console.error("Error in removeNSFWBlock:", error);
        }
    }

    const observer = new MutationObserver(removeNSFWBlock);
const contentContainer = document.documentElement;
    observer.observe(contentContainer, {
        childList: true,
        subtree: true,
        attributes: false
    });

    const shredditCheckInterval = setInterval(() => {
        if (!document.querySelector('shreddit-app')) {
            observer.disconnect();
            clearInterval(shredditCheckInterval);
        }
    }, 5000);
})();