-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
36 lines (32 loc) · 1.23 KB
/
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
32
33
34
35
36
chrome.tabs.onActivated.addListener(async () => {
await checkAndRemoveArticles();
});
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete') {
await checkAndRemoveArticles();
}
});
async function checkAndRemoveArticles() {
let queryOptions = { active: true, currentWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
if (tab.url && tab.url.includes("https://news.google.com")) {
chrome.storage.local.get(['namesList'], function(result) {
if (result.namesList && result.namesList.length > 0) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: removeArticles,
args: [result.namesList]
});
console.log("Removing articles for authors: ", result.namesList);
}
});
}
}
function removeArticles(namesList) {
// This function will be serialized and executed in the context of the tab.
// So, we cannot access any variables or functions defined outside of it.
namesList.forEach(word => {
// Call removeArticle for each word in the list
removeArticle(word);
});
}