Reddit Cleanup

Hide Reddit elements to hide/clear (Check code to configure what to hide).

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         Reddit Cleanup
// @description  Hide Reddit elements to hide/clear (Check code to configure what to hide).
// @author       senji
// @version      1.0
// @license      GNU GPLv3
// @namespace    http://tampermonkey.net/
// @match        *://*.reddit.com/*
// @grant        none
// @run-at       document-start
// @icon         https://files.catbox.moe/7ovpr1.png
// ==/UserScript==

(function () {
    'use strict';

    // replace values with 'true' or 'false' depending on what you want to hide //
    const clearRecentSearches = true;
    const hideRecentPosts = true;

    // sidebar
    const hideEntireSidebar = false;
    const hideStartCommunity = true;
    const hideGamesOnReddit = true;
    const hideCustomFeeds = true;
    const hideRecentSubs = true;
    const hideCommunities = true;
    const hideRedditResources = true;

    if (!window.location.hostname.endsWith('reddit.com')) return;

    // clears your recent searches from the search bar
    if (clearRecentSearches) {
        localStorage.removeItem('recent-searches-store');
    }

    let css = '';

    // hides entire sidebar (overrides other sidebar options)
    if (hideEntireSidebar) {

        css += `
            #flex-left-nav-container {
                display: none !important;
            }
        `;

    } else {

        // hides Explore button in sidebar
        if (hideStartCommunity) {
            css += `
                li[slot="sr-creation-entrypoint-experiment"] {
                    display: none !important;
                }
            `;
        }

        // hides the Reddit Games tab on the sidebar
        if (hideGamesOnReddit) {
            css += `
                faceplate-tracker[noun="games_drawer"],
                faceplate-tracker[noun="games_drawer"] + hr {
                    display: none !important;
                }
            `;
        }

        if (hideCustomFeeds) {
            css += `
                faceplate-expandable-section-helper:has(> details > summary[aria-controls="multireddits_section"]),
                faceplate-expandable-section-helper:has(> details > summary[aria-controls="multireddits_section"]) + hr {
                    display: none !important;
                }
            `;
        }

        // hides your recently visited subreddits on the sidebar
        if (hideRecentSubs) {
            css += `
                #recent-communities-section {
                    display: none !important;
                }
            `;
        }

        // hides your communities (the subs you're in) subreddits on the sidebar
        if (hideCommunities) {
            css += `
                details:has(> summary[aria-controls="communities_section"]),
                faceplate-loader[name^="CommunityCreationFlow"],
                faceplate-partial[name^="CommunityCreationFlow"],
                faceplate-partial[name^="CommunityCreationFlow"] + hr {
                    display: none !important;
                }
            `;
        }

        // hides the Reddit resources section on the sidebar
        if (hideRedditResources) {
            css += `
                nav[aria-label="Reddit resources"] {
                    display: none !important;
                }
            `;
        }

    }

    // hides your recently visited posts on reddit homepage
    if (hideRecentPosts) {
        css += `
            recent-posts,
            [recent-post-ids] {
                display: none !important;
            }
        `;
    }

    // other stuff to hide
    css += `
        a[href="https://redditinc.com"] {
            display: none !important;
        }

        .legal-links {
            display: none !important;
        }

        [data-part="advertise"] {
            display: none !important;
        }
    `;


    if (css.trim()) {
        const style = document.createElement('style');
        style.textContent = css;
        document.documentElement.appendChild(style);
    }

})();