Replace preview with i

Replace preview with i in Reddit image URLs

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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