Skip to content

Instantly share code, notes, and snippets.

@f-steff
Last active January 4, 2025 01:09
Show Gist options
  • Save f-steff/cd4c5fafc574e5595fc7a153516792ab to your computer and use it in GitHub Desktop.
Save f-steff/cd4c5fafc574e5595fc7a153516792ab to your computer and use it in GitHub Desktop.
Userscript for Reddit bug workaround to allow posting on the r/userscript subreddit

Reddit bug workaround to allow posting on the r/userscript subreddit

This userscript addresses a persistent issue with the new Reddit interface that specifically affects the r/userscripts subreddit. The problem prevents users from accessing the post editor or submitting posts in browser-based versions of Reddit. Instead, users encounter Reddit's "Page not found" error page, even though the URL for the post editor appears to be correct.

The issue has been observed across multiple platforms and browsers, including MacBook, PC, and mobile devices, and persists regardless of the network used (e.g., home Wi-Fi or mobile data). Interestingly, other subreddits are unaffected, and posting via the Reddit mobile app works without issues. It was eventually discovered that switching to the old Reddit interface resolves this problem.

Script Functionality

This userscript modifies the "Create Post" button on the r/userscripts subreddit to redirect users to the old Reddit interface for creating posts.

This change ensures that users can bypass the problem entirely by using the old interface, where the post editor works as expected.

Once the post is completed using the old interface, the interfaces reverts to the new interface.

Installation

  1. Install a Userscript Manager:

  2. Create a New Script:

    Either:

    • Open the userscript manager and create a new script.
    • Copy and paste the script code into the editor.

    Or:

    Attempt automatic install

  3. Save and Enable:

    • Save the script and ensure it is active.

The script is currently targeted to the r/userscripts subreddit at at the moment its the only subreddit with the problem, but new subreddits can quikly be supported by adding the appropriate @match header.

// ==UserScript==
// @name Reddit bug workaround to allow posting on the r/userscript subreddit.
// @namespace https://gist.github.com/f-steff
// @version 1.2
// @description Redirects Reddit's submit page for r/userscripts to the old Reddit interface to fix the bug accessing the new interfaces's submit page for the subreddit.
// @author Flemming Steffensen
// @license MIT
// @match https://www.reddit.com/r/userscripts/*
// @match https://old.reddit.com/r/*/comments/*
// @grant none
// @homepageURL https://gist.github.com/f-steff/cd4c5fafc574e5595fc7a153516792ab
// @updateURL https://gist.githubusercontent.com/f-steff/cd4c5fafc574e5595fc7a153516792ab/raw/RedditUserscriptSubredditSubmitWorkaround.user.js
// @downloadURL https://gist.githubusercontent.com/f-steff/cd4c5fafc574e5595fc7a153516792ab/raw/RedditUserscriptSubredditSubmitWorkaround.user.js
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// Redirect old.reddit.com comment links to www.reddit.com
if (window.location.href.includes('old.reddit.com') && window.location.href.includes('/comments/')) {
window.location.href = window.location.href.replace('old.reddit.com', 'www.reddit.com');
}
// Function to modify the "Create Post" button
function modifyCreatePostButton() {
const createPostButton = document.querySelector('a[data-testid="create-post"]');
if (createPostButton && createPostButton.href.includes('www.reddit.com')) {
createPostButton.href = createPostButton.href.replace('www.reddit.com', 'old.reddit.com');
}
}
// Ensure the DOM is fully loaded before running
function init() {
modifyCreatePostButton();
// Observe for dynamic changes to the page and reapply the modification if needed
const observer = new MutationObserver(() => {
modifyCreatePostButton();
});
observer.observe(document.body, { childList: true, subtree: true });
}
if (window.location.href.includes('/r/userscripts/')) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
}
})();
1.0 Initial version
1.1 Changed @run-at to ensure page is fully loaded before modification. New subreddits with similar errors can now be supported by just adding a new @match string.
1.2 Now returns to the new interface after posting using the old interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment