Reddit spoiler blur remover

Remove all blur on spoiler images while keeping the NSFW setting. Supports external images too.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit spoiler blur remover
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Remove all blur on spoiler images while keeping the NSFW setting. Supports external images too.
// @author       violhain
// @match        https://*.reddit.com/*
// @grant        none
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==

// Prevents script to load twice as Reddit uses iframes
if (window.top != window.self) { return false; }

(function() {
    'use strict';
    /* globals $ */

    $(document).ready(function() {
        console.log('Spoiler reveal activated');

        const reveal = () => {
            $('div.Post').each(function() {
                // Ignore NSFW posts
                if (!$(this).text().match(/nsfw/)) {
                    // Click on the spoiler reveal on individual posts
                    $(this).find('button:contains("spoiler")').parent().siblings('a').find('*').click();
                    let postImg = $(this).find('img[alt="Post image"]');
                    // Checks if the post is a spoiler
                    if (postImg.attr('src') && postImg.attr('src').match(/blur/)) {
                        // Checks if the image is external, replace the image without blur
                        if ($(this).find('a.styled-outbound-link').attr('href') && $(this).find('a.styled-outbound-link').attr('href').match(/\.(jpg|png)$/).length > 0) {
                            postImg.attr('src', $(this).find('a.styled-outbound-link').attr('href'));
                        } else {
                            postImg.attr('src', postImg.attr('src').replace('/preview','/i'));
                        }
                        // Remove blur CSS filter + fix dimensions
                        postImg.css('filter','none').css('width','auto').css('height','auto');
                    }
                }
            });
        }

        reveal();
        window.onscroll = function(ev) {
            reveal();
        };
    });

})();