zomboza / Old Reddit Image Loader

// ==UserScript==
// @name Old Reddit Image Loader
// @namespace Tampermonkey Scripts
// @match *://www.reddit.com/*
// @grant none
// @version 1.0
// @author -
// @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @description 02/04/2026, 21:52:47 PM
// ==/UserScript==

(function () {
  "use strict";

  function runScript() {
    // Your logic here (e.g., button click)
    [...document.querySelectorAll("a")].forEach(element => {
      if (element.innerHTML == "<image>") {
        const my_img = document.createElement("img");
        my_img.src = element.href;
        my_img.style = "max-width:360px;width:100%";
        element.replaceWith(my_img);
      }
    });
  }

  // Run on initial load
  runScript();

  // Run on SPA navigation (URL change)
  window.addEventListener("popstate", runScript);
  window.addEventListener("hashchange", runScript);

  // Run on DOM changes (Element appeared)
  const observer = new MutationObserver(runScript);
  observer.observe(document.body, {
    childList: true,
    subtree: true
  });
})();