Replace regex with URL parser

This commit is contained in:
Michał Szopiński 2020-07-16 13:15:38 +02:00
parent 0ea2411903
commit 9f06826bed
1 changed files with 6 additions and 9 deletions

View File

@ -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;
}
let urlParser = document.createElement("a");
urlParser.href = details.url;
return {
redirectUrl:
oldReddit + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
};
if (urlParser.hostname == "old.reddit.com") return;
return {redirectUrl: oldReddit + urlParser.pathname};
},
{
urls: [