Pail/background.js

50 lines
1.0 KiB
JavaScript
Raw Normal View History

const oldReddit = "https://old.reddit.com";
2020-07-16 07:52:58 -04:00
const excludedSubdomains = [
"blog.reddit.com",
"mod.reddit.com",
"oauth.reddit.com",
"out.reddit.com"];
const excludedPaths = [
"/chat",
"/gallery",
"/poll",
"/rpan",
"/settings",
"/topics"];
2018-04-25 10:43:21 -04:00
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
2020-07-16 08:45:13 -04:00
const urlParser = document.createElement("a");
2020-07-16 07:15:38 -04:00
urlParser.href = details.url;
if (urlParser.hostname == "old.reddit.com") return;
2020-07-16 07:31:36 -04:00
if (excludedSubdomains.indexOf(urlParser.hostname) != -1) return;
for (const path of excludedPaths)
if (urlParser.pathname.indexOf(path) == 0)
return;
2020-07-16 07:15:38 -04:00
return {redirectUrl: oldReddit + urlParser.pathname};
2018-04-25 10:43:21 -04:00
},
{
urls: [
"*://reddit.com/*",
"*://www.reddit.com/*",
2018-05-03 09:10:45 -04:00
"*://np.reddit.com/*",
2018-06-12 05:21:54 -04:00
"*://new.reddit.com/*",
2018-04-25 10:43:21 -04:00
],
types: [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"object",
"xmlhttprequest",
"other"
]
2018-04-25 10:43:21 -04:00
},
["blocking"]
);