Skip to content

Instantly share code, notes, and snippets.

@pjmore
Created November 12, 2023 07:43
Show Gist options
  • Save pjmore/3512320c60688443244dc883b54200c9 to your computer and use it in GitHub Desktop.
Save pjmore/3512320c60688443244dc883b54200c9 to your computer and use it in GitHub Desktop.
Tampermonkey old reddit redirect
// ==UserScript==
// @name Reddit Old Layout
// @namespace 9bf36c681d35d52913b3bda74ddf6127318ed7b0
// @version 0.1
// @description Forces usage of the old reddit version
// @author Tom Watson
// @match https://reddit.com/*
// @match https://www.reddit.com/*
// @match https://np.reddit.com/*
// @match https://amp.reddit.com/*
// @match https://i.reddit.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
const excludedPaths = [
/^\/media/,
/^\/poll/,
/^\/rpan/,
/^\/settings/,
/^\/topics/,
/^\/community-points/,
/^\/r\/[a-zA-Z0-9_]+\/s\/.*/, // eg https://reddit.com/r/comics/s/TjDGhcl22d
/^\/appeals?/,
/\/r\/.*\/s\//,
];
const oldReddit = "https://old.reddit.com";
const imageUrlHostnames = ["preview.redd.it", "i.redd.it"];
(function () {
'use strict';
console.log("Handling the url " + window.location.href);
const url = new URL(window.location.href);
if (url.hostname === "old.reddit.com"){
console.log("Was already on old reddit. Doing nothing.");
return;
}
for (const hostname of imageUrlHostnames) {
if (url.hostname === hostname) {
console.log("Hostname matched " + hostname + ". Skipping");
return;
}
}
for (const path of excludedPaths) {
if (path.test(url.pathname)){
console.log(`path ${url.pathname} matched the excluded path ${path}`);
return;
}
}
if (url.pathname.indexOf("/gallery") === 0) {
const gallery_redirect = oldReddit + "/comments" + url.pathname.slice("/gallery".length);
console.log(`Redirecting to ${gallery_redirect}`);
document.location.replace(gallery_redirect)
}else{
const redirect = oldReddit + url.pathname + url.search + url.hash;
console.log(`Redirecting to oldreddit ${redirect}`);
document.location.replace(redirect);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment