-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
31 lines (26 loc) · 1019 Bytes
/
background.js
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
let whitelist = [];
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.get(['whitelist'], (result) => {
console.log(result)
whitelist = result.whitelist || [];
});
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete') {
const url = new URL(tab.url);
const domain = url.hostname;
console.log(whitelist)
if ((whitelist.includes(domain) || ['www.wsj.com', 'www.semafor.com', 'www.reuters.com'].includes(domain)) && url.pathname !== '/') {
chrome.tabs.sendMessage(tabId, { action: "showTicker" });
}
}
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "addToWhitelist") {
whitelist.push(request.domain);
chrome.storage.sync.set({ whitelist: whitelist });
} else if (request.action === "removeFromWhitelist") {
whitelist = whitelist.filter(site => site !== request.domain);
chrome.storage.sync.set({ whitelist: whitelist });
}
});