From 9f06826beda51d97650f22e477a0a35f0b772038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 13:15:38 +0200 Subject: [PATCH 01/10] Replace regex with URL parser --- background.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/background.js b/background.js index 09a1c2f..9c28008 100644 --- a/background.js +++ b/background.js @@ -2,15 +2,12 @@ const oldReddit = "https://old.reddit.com"; chrome.webRequest.onBeforeRequest.addListener( function(details) { - // Exclude poll pages - if (details.url.match(/^https?:\/\/(www\.)*reddit.com\/poll/)) { - return; - } - - return { - redirectUrl: - oldReddit + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1] - }; + let urlParser = document.createElement("a"); + urlParser.href = details.url; + + if (urlParser.hostname == "old.reddit.com") return; + + return {redirectUrl: oldReddit + urlParser.pathname}; }, { urls: [ From 90181d412526e99435fb56dd99f0f456b94f55fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 13:31:36 +0200 Subject: [PATCH 02/10] Add exception system --- background.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/background.js b/background.js index 9c28008..cefa8c1 100644 --- a/background.js +++ b/background.js @@ -1,4 +1,6 @@ const oldReddit = "https://old.reddit.com"; +const excludedSubdomains = ["blog.reddit.com", "oauth.reddit.com", "out.reddit.com"]; +const excludedPaths = ["/poll", "/gallery", "/rpan", "/settings"]; chrome.webRequest.onBeforeRequest.addListener( function(details) { @@ -7,6 +9,12 @@ chrome.webRequest.onBeforeRequest.addListener( if (urlParser.hostname == "old.reddit.com") return; + if (excludedSubdomains.indexOf(urlParser.hostname) != -1) return; + + for (const path of excludedPaths) + if (urlParser.pathname.indexOf(path) == 0) + return; + return {redirectUrl: oldReddit + urlParser.pathname}; }, { From 9dc68e90297d2d357a2eeec8906e5571a4619e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 13:52:58 +0200 Subject: [PATCH 03/10] Add more exceptions --- background.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index cefa8c1..651983f 100644 --- a/background.js +++ b/background.js @@ -1,6 +1,16 @@ const oldReddit = "https://old.reddit.com"; -const excludedSubdomains = ["blog.reddit.com", "oauth.reddit.com", "out.reddit.com"]; -const excludedPaths = ["/poll", "/gallery", "/rpan", "/settings"]; +const excludedSubdomains = [ + "blog.reddit.com", + "mod.reddit.com", + "oauth.reddit.com", + "out.reddit.com"]; +const excludedPaths = [ + "/chat", + "/gallery", + "/poll", + "/rpan", + "/settings", + "/topics"]; chrome.webRequest.onBeforeRequest.addListener( function(details) { From a986d17e844f487a75688f796790df3760e2db86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 13:58:24 +0200 Subject: [PATCH 04/10] Bump version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4bf3273..2ec63f4 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.1.4", + "version": "1.1.5", "manifest_version": 2, "background": {"scripts":["background.js"]}, "icons": { From 790ff84ec996c5bf75fddbb3d2a6630b9b514347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 14:45:13 +0200 Subject: [PATCH 05/10] Make parser const --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index 651983f..1a317f7 100644 --- a/background.js +++ b/background.js @@ -14,7 +14,7 @@ const excludedPaths = [ chrome.webRequest.onBeforeRequest.addListener( function(details) { - let urlParser = document.createElement("a"); + const urlParser = document.createElement("a"); urlParser.href = details.url; if (urlParser.hostname == "old.reddit.com") return; From 01a3d69adc2deb400875666b0c366337745264c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 15:01:19 +0200 Subject: [PATCH 06/10] Fix indent --- background.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index 1a317f7..9b83ee7 100644 --- a/background.js +++ b/background.js @@ -21,9 +21,9 @@ chrome.webRequest.onBeforeRequest.addListener( if (excludedSubdomains.indexOf(urlParser.hostname) != -1) return; - for (const path of excludedPaths) - if (urlParser.pathname.indexOf(path) == 0) - return; + for (const path of excludedPaths) { + if (urlParser.pathname.indexOf(path) == 0) return; + } return {redirectUrl: oldReddit + urlParser.pathname}; }, From 2c28b50960b2f508c93d8067898bbaf306bd1a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Thu, 16 Jul 2020 18:56:23 +0200 Subject: [PATCH 07/10] Preserve query string and hash --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index 9b83ee7..97f3ff9 100644 --- a/background.js +++ b/background.js @@ -25,7 +25,7 @@ chrome.webRequest.onBeforeRequest.addListener( if (urlParser.pathname.indexOf(path) == 0) return; } - return {redirectUrl: oldReddit + urlParser.pathname}; + return {redirectUrl: oldReddit + urlParser.pathname + urlParser.search + urlParser.hash}; }, { urls: [ From 629926126eb1149b5636ace05b59067ece1a433f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Fri, 17 Jul 2020 15:19:05 +0200 Subject: [PATCH 08/10] Remove unnecessary exceptions --- background.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/background.js b/background.js index 97f3ff9..a1cee69 100644 --- a/background.js +++ b/background.js @@ -1,11 +1,5 @@ const oldReddit = "https://old.reddit.com"; -const excludedSubdomains = [ - "blog.reddit.com", - "mod.reddit.com", - "oauth.reddit.com", - "out.reddit.com"]; const excludedPaths = [ - "/chat", "/gallery", "/poll", "/rpan", @@ -19,8 +13,6 @@ chrome.webRequest.onBeforeRequest.addListener( if (urlParser.hostname == "old.reddit.com") return; - if (excludedSubdomains.indexOf(urlParser.hostname) != -1) return; - for (const path of excludedPaths) { if (urlParser.pathname.indexOf(path) == 0) return; } From f481bcdbfbe2bc0078301289371b1414cb081c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Sat, 18 Jul 2020 22:01:26 +0200 Subject: [PATCH 09/10] Refactor URL parsing, fix equalities --- background.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/background.js b/background.js index a1cee69..67ff4e2 100644 --- a/background.js +++ b/background.js @@ -8,16 +8,15 @@ const excludedPaths = [ chrome.webRequest.onBeforeRequest.addListener( function(details) { - const urlParser = document.createElement("a"); - urlParser.href = details.url; + const url = new URL(details.url); - if (urlParser.hostname == "old.reddit.com") return; + if (url.hostname === "old.reddit.com") return; for (const path of excludedPaths) { - if (urlParser.pathname.indexOf(path) == 0) return; + if (url.pathname.indexOf(path) === 0) return; } - return {redirectUrl: oldReddit + urlParser.pathname + urlParser.search + urlParser.hash}; + return {redirectUrl: oldReddit + url.pathname + url.search + url.hash}; }, { urls: [ From ce7c67857be1712d62e4c71195af075aee78859a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szopi=C5=84ski?= Date: Sat, 18 Jul 2020 22:01:51 +0200 Subject: [PATCH 10/10] Bump version to 1.2.0 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 2ec63f4..fc9d55e 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.1.5", + "version": "1.2.0", "manifest_version": 2, "background": {"scripts":["background.js"]}, "icons": {