I Fixed the Reddit Feed With This Tiny Script

Small annoyances on your favorite websites can add up over time and cause great frustration. For me, it’s Reddit defaulting to “Best” that does it. Fortunately, with a small amount of determination and a powerful extension, you can fix most such problems.

What’s the Problem?

I held out for a long, long time, but I recently took the plunge and moved over to “new” Reddit. Generally, it’s not as bad as I feared, and the UI is pretty good for the most part. But one issue annoys me to a significant degree: the default post order.

Reddit’s home page showing posts in a “Best” sort order.

On the home feed and individual subreddit feeds, posts are shown in a “Best” sort order. This is an opaque setting and, much like the “for you” algorithm on X or YouTube’s home feed, it acts more to promote content than serve a particular need. I can’t count the number of times I’ve been drawn to a post’s title, only to turn annoyed when I see it is weeks or months old.

Even when I spot what’s wrong, it takes two clicks to move from “Best” to “New,” and it disrupts my flow. But thanks to a bit of effort, this is a problem no more.

Related

5 Reasons You Should Ignore the For You Page on All Social Media

What’s “for me” anyway?

How to Fix the Feed

If you know any JavaScript, you may already be thinking about how to solve this issue. Using this programming language, you can add functionality to a website, modify its colors and fonts, or even remove content you’re not interested in. For these changes to be visible to everyone, you’d need access to the website’s backend, but you can use your browser to make these kinds of changes to your personal experience on any site.

The key is a browser extension that lets you run your own JavaScript on specific sites. I’m using an extension for Chrome called Tampermonkey:

The Chrome extension page for Tampermonkey.

Most browsers have this feature either built in or available via an extension. In fact, Tampermonkey is available for all major browsers—Chrome, Edge, Safari, and Firefox—so I’d recommend it as your first choice.

Start by downloading Tampermonkey for your browser; I’m using the Chrome version.

Related

How to Install and Manage Extensions in Chrome

Installing and managing extensions in Google Chrome isn’t difficult, but there are some tricks you’ll want to know.

Once you’ve added and enabled the extension, use its menu to “Create a new script.” You should see something looking like this:

A new userscript in Tampermonkey, with boilerplate JavaScript code.

There’s a lot of boilerplate here, and most of it is comments that won’t have a material effect. But you should make sure the “@match” line looks like the following:

        

This tells Tampermonkey to run the script only on the Reddit website. The “*” wildcard means it will run on every page, but the script will take that into account and make sure it only affects the main home page.

Now for the actual script, which should replace the line that reads “// Your code here…:”

        function checkURL() {
    if (window.location.pathname === "https://www.howtogeek.com/") {
        window.location.replace("//www.reddit.com/new");
    }
}

let currentUrl = location.href;
checkURL();

setInterval(() => {
    if (location.href !== currentUrl) {
        currentUrl = location.href;
        checkURL();
    }
}, 500);

You don’t need a deep understanding of what’s going on here, but I’ll explain a few key parts.

The checkURL function does the main work. First, it checks if the page’s URL has just a single forward slash after the domain name. If so, we’re on the home page. It then calls window.location.replace(), simply adding “new” to the end of the URL. This instructs your browser to load the URL, which is the home page, just sorted by most recent posts instead of the default.

The rest of the script makes sure this check happens on a regular basis: twice each second. Ideally, this would not be necessary; the check should only need to take place when the URL changes and the page initially loads. However, due to the way in which Reddit loads pages, the script needs to just check on a regular basis instead. It’s a “brute force” approach, but the code does so little work that we can get away with it.

Save your script and close the Tampermonkey tab, then switch over to Reddit and try loading the home page. You should now see that, instead of the default “Best” feed, you’re viewing “New,” a vastly superior experience!

What Else Can You Fix?

You don’t need to change the code much to accommodate subreddit home pages, too. Just add another condition to the checkURL() function, which treats subreddit URLs in a similar way:

        function checkURL() {
    let match;

    if (window.location.pathname === "https://www.howtogeek.com/") {
        window.location.replace("//www.reddit.com/new");
    } else if (match = window.location.pathname.match("(/r/[^/]+)/$")) {
        window.location.replace("//www.reddit.com" + match[1] + "/new/");
    }
}

This check is a bit more complicated because you need to test for a pattern that could match many different URLs, rather than one fixed URL. The call to window.location.pathname.match() uses a regular expression. Again, the details are not hugely important; the key thing is that this check matches URLs that look like “/r/[subreddit]/” and adds “new/” to the end of them.

Related

How Do You Actually Use Regex?

Regex, short for regular expression, is often used in programming languages for matching patterns in strings, find and replace, input validation, and reformatting text.

Once you’ve set this extension up, the world is your oyster, provided you can learn a little JavaScript. With Tampermonkey, or a similar extension, and some determination, you can fix all sorts of problems with sites you use regularly. Remove unwanted elements, reorganize navigation, force dark mode, stop videos playing, and more.

The only real limits depend on how well each site is structured. For example, X (Twitter) uses the same URL for both its “For you” view and its “Following” one, meaning it’s much more complicated to work with. On the other hand, YouTube is better behaved, with distinct URLs for its home page and subscriptions feed.

So fixing up sites involves some investigation and a bit of experimentation, but the improvements you can add make it well worth your time.

Related

6 JavaScript Snippets to Polish Your Site

Quick and easy wins for any site you’re building.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top