-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
30 lines (26 loc) · 1.04 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
// Keep track of content script status
let contentScriptStatus = new Map();
// Listen for connection status from content scripts
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'contentScriptReady') {
contentScriptStatus.set(sender.tab.id, true);
sendResponse({ success: true });
}
return true;
});
// Listen for tab updates
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url && (tab.url.includes('twitter.com') || tab.url.includes('x.com'))) {
// Reset content script status for this tab
contentScriptStatus.set(tabId, false);
// Inject the content script
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['content.js']
}).catch(error => console.error('Error injecting content script:', error));
}
});
// Clean up when tabs are closed
chrome.tabs.onRemoved.addListener((tabId) => {
contentScriptStatus.delete(tabId);
});