Replace preview with i

Replace preview with i in Reddit image URLs

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==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);
})();