-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
55 lines (47 loc) · 2.05 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var loggedin = false;
// Function to update the icon based on the URL
function updateIconForTab(tab) {
chrome.cookies.get({ url: "https://cat.arisamiga.rocks", name: "connect.sid" }, cookie => {
if (cookie) {
// If logged in, decide which popup to use based on the URL
if (tab.url && tab.url.includes("https://catwar.su/cw3")) {
chrome.action.setIcon({ path: "./icons/icon.png", tabId: tab.id });
chrome.action.setPopup({ tabId: tab.id, popup: "popup.html" }); // Assuming "popup.html" is your popup
//%%FirefoxSB:popup.html%%
} else {
chrome.action.setIcon({ path: "./icons/grayscale_icon.png", tabId: tab.id });
chrome.action.setPopup({ tabId: tab.id, popup: "dpopup.html" }); // Setting popup to an empty string disables it
//%%FirefoxSB:dpopup.html%%
}
}
else {
// If not logged in, always use main.html as the popup
chrome.action.setPopup({ tabId: tab.id, popup: "main.html" });
chrome.action.setIcon({ path: "./icons/icon.png", tabId: tab.id });
//%%FirefoxSB:main.html%%
}
});
}
// Listen for tab updates
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// Check if the tab is completed loading to avoid multiple triggers
if (changeInfo.status === 'complete') {
updateIconForTab(tab);
}
});
// Listen for tab activation
chrome.tabs.onActivated.addListener(activeInfo => {
chrome.tabs.get(activeInfo.tabId, updateIconForTab);
});
// Listen for messages from the content script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "loggedinreload") {
// Get active tab
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
updateIconForTab(tabs[0]);
// Reload the page
sendResponse({ success: true });
});
return true;
}
});