Refactor URL parsing, fix equalities

This commit is contained in:
Michał Szopiński 2020-07-18 22:01:26 +02:00
parent 629926126e
commit f481bcdbfb
1 changed files with 4 additions and 5 deletions

View File

@ -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: [