Better Reddit Image Previews

Fixes issues with image carousels having images that don't fit the height. As well, image previews, on clicking, instead of linking to the image, link to the thread, where you have to click on the image yet again to view it in isolation.

当前为 2021-09-21 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Better Reddit Image Previews
// @namespace    https://lawrenzo.com/p/better-reddit-image-previews
// @version      0.1.1
// @description  Fixes issues with image carousels having images that don't fit the height. As well, image previews, on clicking, instead of linking to the image, link to the thread, where you have to click on the image yet again to view it in isolation.
// @author       Lawrence Sim
// @license      WTFPL (http://www.wtfpl.net)
// @grant        none
// @match        *://*.reddit.com/*
// ==/UserScript==
'use strict';
(function() {
    var fixImages = function() {
        document.querySelectorAll("[data-click-id='background'] div[tabindex='0'] ul li figure img")
            .forEach(function(img) {
                if(img.getAttribute("ifix")) return;
                img.style.height = "100%";
                img.parentElement.style.height = "100%";
                img.addEventListener("click", function(evt) {
                    window.open(img.getAttribute("src"));
                    evt.stopPropagation();
                });
                img.setAttribute("ifix", 1);
            });
        document.querySelectorAll("[data-click-id='background'] img[alt='Post image']")
            .forEach(function(img) {
                if(img.getAttribute("ifix")) return;
                img.addEventListener("click", function(evt) {
                    window.open(img.getAttribute("src"));
                    evt.stopPropagation();
                    evt.preventDefault();
                });
                img.setAttribute("ifix", 1);
            });
    }
    fixImages();
    (new MutationObserver(fixImages)).observe(
        document.body,
        {childList:true, subtree:true}
    );
})();