Skip to content

Instantly share code, notes, and snippets.

@zudsniper
Forked from pjmore/redirect.js
Last active October 23, 2024 00:18

Revisions

  1. zudsniper revised this gist Oct 23, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions reddit-redirect.user.js
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    // @name Old Reddit Redirect
    // @namespace zod.tf
    // @version 0.1
    // @description Forces usage of the old reddit version
    // @author Tom Watson
    // @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/*
  2. zudsniper renamed this gist Oct 23, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions redirect.js → reddit-redirect.user.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // ==UserScript==
    // @name Reddit Old Layout
    // @namespace 9bf36c681d35d52913b3bda74ddf6127318ed7b0
    // @name Old Reddit Redirect
    // @namespace zod.tf
    // @version 0.1
    // @description Forces usage of the old reddit version
    // @author Tom Watson
  3. @pjmore pjmore created this gist Nov 12, 2023.
    66 changes: 66 additions & 0 deletions redirect.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    // ==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);
    }

    })();