Bring Back Old Reddit (with image fix)

Redirects reddit.com → old.reddit.com, but opens direct image URLs when clicking media links.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Bring Back Old Reddit (with image fix)
// @namespace   https://greasyfork.org/en/users/1475555-xenon1234
// @description Redirects reddit.com → old.reddit.com, but opens direct image URLs when clicking media links.
// @match       https://www.reddit.com/*
// @exclude     https://www.reddit.com/poll/*
// @run-at      document-start
// @grant       none
// @version     1.0
// @icon        https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-76x76.png
// @license     MIT
// ==/UserScript==

(function() {
  'use strict';
  const href = window.location.href;
  const params = new URLSearchParams(window.location.search);
  const img = params.get('url');

  // If there's a `?url=` param pointing at an image file, go there directly:
  if (img && /\.(?:png|jpe?g|gif|webp|bmp)(?:\?.*)?$/i.test(img)) {
      document.open();
      document.write(`
        <!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8">
            <title>Reddit Image ${img}</title>
            <style>body{margin:0;background:#000}img{display:block;max-width:100%;height:auto;margin:0 auto}</style>
          </head>
          <body>
            <img src="${img}">
          </body>
        </html>
      `);
      document.close();
      return;
  } else {
    // Otherwise, send everything else to old.reddit.com
    window.location.replace(
      href.replace(/^https?:\/\/www\.reddit\.com/, 'https://old.reddit.com')
    );
  }
})();