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.

目前為 2021-12-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Better Reddit Image Previews
// @namespace    https://lawrenzo.com/p/better-reddit-image-previews
// @version      0.1.3
// @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").replace("preview.redd.it", "i.redd.it"));
                        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").replace("preview.redd.it", "i.redd.it"));
                        evt.stopPropagation();
                        evt.preventDefault();
                    });
                    img.setAttribute("ifix", 1);
                });
        });
    }
    fixImages([{target: document.body}]);
    (new MutationObserver(fixImages)).observe(
        document.body,
        {childList:true, subtree:true}
    );
})();