Better Reddit Image Previews

Fixes issues with reddit image previews. Specifically, clicking image preview now links directly to image (instead of thread) and fits height of image previews in carousel so they don't get clipped out.

اعتبارا من 26-10-2021. شاهد أحدث إصدار.

// ==UserScript==
// @name         Better Reddit Image Previews
// @namespace    https://lawrenzo.com/p/better-reddit-image-previews
// @version      0.1.2
// @description  Fixes issues with reddit image previews. Specifically, clicking image preview now links directly to image (instead of thread) and fits height of image previews in carousel so they don't get clipped out.
// @author       Lawrence Sim
// @license      WTFPL (http://www.wtfpl.net)
// @grant        none
// @match        *://*.reddit.com/*
// ==/UserScript==
'use strict';
(function() {
    var fixImages = mutated => {
        mutated.forEach(mutant => {
            mutant.target.querySelectorAll("[data-click-id='background'] div[tabindex='0'] ul li figure img")
                .forEach(img => {
                    if(img.getAttribute("ifix")) return;
                    img.style.height = "100%";
                    img.parentElement.style.height = "100%";
                    img.addEventListener("click", evt => {
                        window.open(img.getAttribute("src"));
                        evt.stopPropagation();
                    });
                    img.setAttribute("ifix", 1);
                });
            mutant.target.querySelectorAll("[data-click-id='background'] img[alt='Post image']")
                .forEach(img => {
                    if(img.getAttribute("ifix")) return;
                    img.addEventListener("click", evt => {
                        window.open(img.getAttribute("src"));
                        evt.stopPropagation();
                        evt.preventDefault();
                    });
                    img.setAttribute("ifix", 1);
                });
        });
    }
    fixImages([{target: document.body}]);
    (new MutationObserver(fixImages)).observe(
        document.body,
        {childList:true, subtree:true}
    );
})();