From 7e41360e60c22c09ae9c366e60d3ef3a607804d3 Mon Sep 17 00:00:00 2001 From: Tom Watson Date: Sun, 7 Nov 2021 10:07:53 +0100 Subject: [PATCH] add unique redirect for gallery links Closes https://github.com/tom-james-watson/old-reddit-redirect/issues/60 A gallery link in the form https://www.reddit.com/gallery/qnjjvh can be redirected to https://old.reddit.com/r/OnePiece/comments/qnjjvh/marines_as_shinigami_by_norridzuan_art. We only have the id to work with, but reddit will actually redirect https://old.reddit.com/qnjjvh to the full url, so we can just redirect to that instead. --- background.js | 12 +++++++++++- manifest.json | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index a1e4115..e38bf9a 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,11 @@ const oldReddit = "https://old.reddit.com"; -const excludedPaths = ["/gallery", "/poll", "/rpan", "/settings", "/topics", "/community-points"]; +const excludedPaths = [ + "/poll", + "/rpan", + "/settings", + "/topics", + "/community-points", +]; chrome.webRequest.onBeforeRequest.addListener( function (details) { @@ -11,6 +17,10 @@ chrome.webRequest.onBeforeRequest.addListener( if (url.pathname.indexOf(path) === 0) return; } + if (url.pathname.indexOf("/gallery") === 0) { + return { redirectUrl: oldReddit + url.pathname.slice("/gallery".length) }; + } + return { redirectUrl: oldReddit + url.pathname + url.search + url.hash }; }, { diff --git a/manifest.json b/manifest.json index f3cdc2b..181d060 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Old Reddit Redirect", "description": "Ensure Reddit always loads the old design", - "version": "1.5.1", + "version": "1.6.0", "manifest_version": 2, "background": { "scripts": ["background.js"] }, "icons": {