Replace preview with i

Replace preview with i in Reddit image URLs

Verze ze dne 26. 03. 2023. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Replace preview with i
// @namespace    https://i.redd.it
// @version      1.0
// @description  Replace preview with i in Reddit image URLs
// @match        *://*/*
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';
    // Define a function to replace image URLs
    function replaceImageURLs() {
        // Get all images on the page
        var images = document.getElementsByTagName("img");
        // Loop through each image
        for (var i = 0; i < images.length; i++) {
            // Get the current src value
            var src = images[i].src;
            // Check if it contains preview.redd.it
            if (src.includes("preview.redd.it")) {
                // Replace preview with i
                var newSrc = src.replace("preview", "i");
                // Set the new src value
                images[i].src = newSrc;
            }
        }
    }
    // Create a mutation observer instance
    var observer = new MutationObserver(replaceImageURLs);
    // Define the observer options: observe all child nodes and attributes of the body element
    var options = {childList: true, subtree: true, attributes: true};
    // Start observing the body element for changes
    observer.observe(document.body, options);
})();