forked from tom-james-watson/old-reddit-redirect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
56 lines (51 loc) · 1.34 KB
/
background.js
File metadata and controls
56 lines (51 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const oldReddit = "https://old.reddit.com";
var disabled = false;
// Redirect requests
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
// Check if disabled
if(disabled) {
return;
}
// Exclude poll pages
if (/^https?:\/\/(www\.)*reddit.com\/poll/.test(details.url)) {
return;
}
return {
redirectUrl:
oldReddit + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
};
},
{
urls: [
"*://reddit.com/*",
"*://www.reddit.com/*",
"*://np.reddit.com/*",
"*://new.reddit.com/*",
],
types: [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"object",
"xmlhttprequest",
"other"
]
},
["blocking"]
);
// Browser Action
chrome.browserAction.setTitle({"title": "Old Reddit Redirect (Enabled)"});
chrome.browserAction.onClicked.addListener(() => {
disabled = !disabled;
// Set icon and name
if(disabled) {
chrome.browserAction.setIcon({"path": {"48": "img/disabledicon48.png", "128": "img/disabledicon128.png"}});
chrome.browserAction.setTitle({"title": "Old Reddit Redirect (Disabled)"});
} else {
chrome.browserAction.setIcon({"path": {"48": "img/icon48.png", "128": "img/icon128.png"}});
chrome.browserAction.setTitle({"title": "Old Reddit Redirect (Enabled)"});
}
});