Shreddit Unblur Images NSFW

Unblur images and redgifs iframes in sh.reddit.com

目前为 2024-01-27 提交的版本。查看 最新版本

// ==UserScript==
// @name            Shreddit Unblur Images NSFW
// @namespace       https://greasyfork.org/users/821661
// @match           https://www.reddit.com/*
// @match           https://sh.reddit.com/*
// @grant           GM_addStyle
// @version         1.1
// @author          hdyzen
// @description     Unblur images and redgifs iframes in sh.reddit.com
// @license         MIT
// ==/UserScript==
'use strict';

// Verify if Shreddit
const shReddit = document.querySelector('shreddit-app');
if (!shReddit) return;

// Regex for match id image
const regexIdImg = /https:\/\/.*\/(.*)\?/;

// Interval time
const sleepTime = 2000;

// Unblur images, redgifs iframes
async function checkMedia() {
    while (true) {
        await new Promise(resolve => setTimeout(resolve, sleepTime));
        const slots = document.querySelectorAll('shreddit-blurred-container :is([slot="blurred"], [slot="revealed"])');
        slots.forEach(slot => {
            if (slot.slot === 'blurred' && slot.nextElementSibling?.slot !== 'revealed') {
                const img = slot.querySelector('img.object-contain');
                console.log(img.src);
                img.src = `https://i.redd.it/${img.src.match(regexIdImg)[1]}`;
                slot.closest('shreddit-blurred-container').outerHTML = slot.innerHTML;

                slot.addEventListener('click', () => {
                    console.log('clicked');
                });

                return;
            } else if (slot.slot === 'revealed') {
                slot.closest('shreddit-blurred-container').outerHTML = slot.innerHTML;
                slot.addEventListener('click', () => {
                    console.log('clicked');
                });
            }
        });
    }
}
checkMedia();

GM_addStyle(`
body {
    overflow: unset !important;
    pointer-events: unset !important;
}
shreddit-async-loader[bundlename="desktop_rpl_nsfw_blocking_modal"], div[style="position: fixed; inset: 0px; backdrop-filter: blur(4px);"]  {
    display: none !important;
}
`);