-
-
Save zudsniper/01ab395934cf785d688afc2c392cdf1d to your computer and use it in GitHub Desktop.
reddit to old.reddit everywhere userscript (fork from Tom Watson's script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Old Reddit Redirect | |
// @namespace zod.tf | |
// @version 0.1 | |
// @description Forces usage of the old reddit version (from Tom Watson project, forked) | |
// @author zudsniper | |
// @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