Replace regex with URL parser
This commit is contained in:
parent
0ea2411903
commit
9f06826bed
|
@ -2,15 +2,12 @@ const oldReddit = "https://old.reddit.com";
|
||||||
|
|
||||||
chrome.webRequest.onBeforeRequest.addListener(
|
chrome.webRequest.onBeforeRequest.addListener(
|
||||||
function(details) {
|
function(details) {
|
||||||
// Exclude poll pages
|
let urlParser = document.createElement("a");
|
||||||
if (details.url.match(/^https?:\/\/(www\.)*reddit.com\/poll/)) {
|
urlParser.href = details.url;
|
||||||
return;
|
|
||||||
}
|
if (urlParser.hostname == "old.reddit.com") return;
|
||||||
|
|
||||||
return {
|
return {redirectUrl: oldReddit + urlParser.pathname};
|
||||||
redirectUrl:
|
|
||||||
oldReddit + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
urls: [
|
urls: [
|
||||||
|
|
Loading…
Reference in New Issue