Reddit Bypass Enhancer

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

目前为 2025-01-22 提交的版本。查看 最新版本

// ==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://gf.qytechs.cn/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',
    };

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

    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();
        });
      }
       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);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址