Pail/background.js

37 lines
820 B
JavaScript
Raw Normal View History

const oldReddit = "https://old.reddit.com";
2021-01-23 08:40:00 -05:00
const excludedPaths = ["/gallery", "/poll", "/rpan", "/settings", "/topics"];
2018-04-25 10:43:21 -04:00
chrome.webRequest.onBeforeRequest.addListener(
2021-01-23 08:40:00 -05:00
function (details) {
2020-07-18 16:01:26 -04:00
const url = new URL(details.url);
2021-01-23 08:40:00 -05:00
2020-07-18 16:01:26 -04:00
if (url.hostname === "old.reddit.com") return;
2021-01-23 08:40:00 -05:00
2020-07-16 09:01:19 -04:00
for (const path of excludedPaths) {
2020-07-18 16:01:26 -04:00
if (url.pathname.indexOf(path) === 0) return;
2018-11-20 01:59:07 -05:00
}
2021-01-23 08:40:00 -05:00
return { redirectUrl: oldReddit + url.pathname + url.search + url.hash };
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/*",
"*://amp.reddit.com/*",
"*://i.reddit.com/*",
2018-04-25 10:43:21 -04:00
],
types: [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"object",
"xmlhttprequest",
2021-01-23 08:40:00 -05:00
"other",
],
2018-04-25 10:43:21 -04:00
},
["blocking"]
);