Greasy Fork is available in English.

Force new.reddit.com

Force new.reddit.com.

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 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.

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.

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

// ==UserScript==
// @name         Force new.reddit.com
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Force new.reddit.com.
// @author       You
// @match        https://new.reddit.com/*
// @grant        none
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
        work();
    } else {
        document.addEventListener("DOMContentLoaded", function(event) {
            work();
        });
    }
})();

function work() {

    // Check the condition to prevent a redirect loop
    const shouldNotRedirect = document.querySelectorAll('shreddit-app').length === 0;

    // Function to check if we're already on the messages page
    function isOnMessagesPage() {
        const url = window.location.href.split('?')[0];
        return url === 'https://new.reddit.com/message/messages';
    }

    // If shouldNotRedirect is true and we are not on the messages page, exit the script
    if (shouldNotRedirect && !isOnMessagesPage()) {
        console.log("don't redirect", document.querySelectorAll('shreddit-app'), window.location.href, 'https://new.reddit.com/message/messages' === window.location.href);
        return;
    }

    // Check if we're not on the messages page
    if (!isOnMessagesPage()) {
        // Save the current URL in sessionStorage if not already set
        if (!sessionStorage.getItem('originalUrl')) {
            sessionStorage.setItem('originalUrl', window.location.href);
        }

        // Redirect to the messages page with a full page refresh
        document.location.replace('https://new.reddit.com/message/messages');
    } else {
        // We are on the messages page

        // Retrieve the original URL from sessionStorage
        const originalUrl = sessionStorage.getItem('originalUrl');

        // If there is an original URL stored, navigate back to it
        if (originalUrl) {
            console.log("nav back", originalUrl, window.location.href);
            setTimeout(() => {
                // Use history.pushState to navigate back to the original Reddit page
                history.pushState({}, '', originalUrl);

                // Dispatch a popstate event to notify the React Router of the URL change
                window.dispatchEvent(new PopStateEvent('popstate'));

                // Clear the stored original URL after navigation
                sessionStorage.removeItem('originalUrl');
            }, 1); // Adjust the delay as needed to ensure messages are checked
        }
    }
}