Skip to content

Instantly share code, notes, and snippets.

@msanders
Last active February 21, 2024 14:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save msanders/52700d5c5ed76f1114594ddb862b530e to your computer and use it in GitHub Desktop.
Save msanders/52700d5c5ed76f1114594ddb862b530e to your computer and use it in GitHub Desktop.
Userscript: Old Reddit Redirect
// ==UserScript==
// @name Old Reddit Redirect
// @description Redirects www.reddit.com to the old version of the website
// @downloadURL https://gist.githubusercontent.com/msanders/52700d5c5ed76f1114594ddb862b530e/raw/old-reddit-redirect.user.js
// @updateURL https://gist.githubusercontent.com/msanders/52700d5c5ed76f1114594ddb862b530e/raw/old-reddit-redirect.user.js
// @version 2023.10.19
// @run-at request
// ==/UserScript==
[
{
"id": 1,
"action": { "type": "allow" },
"condition": { "regexFilter": "^https?://www\\.reddit\\.com/media\\?", "resourceTypes": ["main_frame"] }
},
{
"id": 2,
"action": { "type": "allow" },
"condition": { "regexFilter": "^https?://www\\.reddit\\.com/gallery/", "resourceTypes": ["main_frame"] }
},
{
"id": 3,
"action": { "type": "allow" },
"condition": { "regexFilter": "^https?://www\\.reddit\\.com/settings/", "resourceTypes": ["main_frame"] }
},
{
"id": 4,
"action": { "type": "allow" },
"condition": { "regexFilter": "^https?://www\\.reddit\\.com/r/\\w+/s/", "resourceTypes": ["main_frame"] }
},
{
"id": 5,
"action": {
"type": "redirect",
"redirect": {
"transform": { "scheme": "https", "host": "old.reddit.com" }
}
},
"condition": { "regexFilter": "^https?://www\\.reddit\\.com/", "resourceTypes": ["main_frame"] }
}
]
@msanders
Copy link
Author

msanders commented Aug 17, 2023

Compatible with Userscripts for Safari, documentation on declarativeNetRequest available here.

Equivalent rule for Redirector extension:

Reddit redirect

  • Example URL: https://www.reddit.com/example
  • Include pattern: ^https?://www\.reddit\.com(?!/(?:(?:media|gallery|settings)\b|r/\w+/s/))([/#?].*)?$
  • Redirect to: https://old.reddit.com$1
  • Pattern type: Regular Expression
  • Description: Old Reddit Redirect

Both of these methods are faster than using window.location.replace in Greasemonkey, which requires an additional network request even with @run-at document-start.

@sourcevault
Copy link

how do you install it though ?

@msanders
Copy link
Author

msanders commented Sep 6, 2023

To install, open the raw link and follow the prompt on the Userscripts extension modal. Alternatively, you can create a new JavaScript item on the extension page and copy/paste the script. On iOS, go to the same link and tap the puzzle icon in the address bar and then the “Userscripts” menu item. Instructions to install the Userscripts extension can be found here.

Screenshot 2023-09-06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment