-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
35 lines (32 loc) · 1.07 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
// Toggle elements on all open tabs
function toggleElementsOnAllTabs() {
browser.tabs.query({}, function (tabs) {
for (const tab of tabs) {
if (tab.favIconUrl && tab.url.includes("skool.com")) {
browser.tabs.sendMessage(tab.id, { message: "toggle_element" });
}
}
});
}
browser.action.onClicked.addListener(function (tab) {
toggleElementsOnAllTabs();
});
// Add a listener for the message from the content script to toggle elements.
browser.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.message === "toggle_element") {
// Send a message to all open tabs to toggle elements
browser.tabs.query({}, function (tabs) {
for (const tab of tabs) {
browser.tabs.sendMessage(tab.id, {
hideElements: message.hideElements,
});
}
});
}
});
// Add a listener for tab update
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (tab.favIconUrl && tab.url.includes("skool.com")) {
browser.tabs.sendMessage(tab.id, { message: "tab_update" });
}
});