Reddit Sort By New 🆕

Sort Subreddits by "new"

// ==UserScript==
// @name         Reddit Sort By New 🆕
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Sort Subreddits by "new"
// @author       Agreasyforkuser
// @icon         https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const re = /https?:\/\/(?:www\.|old\.|new\.)?reddit\.com/i;
    for (var i=0, l=document.links.length; i<l; i++) {
        if (re.test(document.links[i].href)) {
            var path = document.links[i].pathname;
            if (path === '/' || path.startsWith('/r/')) {
                var pathlen = path.split('/').length - 1 - (path.endsWith('/') ? 1 : 0);
                if ((pathlen <= 2) && (document.links[i].closest('.tabmenu') === null)) {
                    document.links[i].href += path.endsWith('/') ? 'new/' : '/new/';
                }
            }
        }
    }
})();