-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
49 lines (44 loc) · 1.5 KB
/
background.js
File metadata and controls
49 lines (44 loc) · 1.5 KB
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
// X Country Filter - Background Service Worker
// Initialize default settings on install
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
chrome.storage.sync.set({
blockedCountries: [],
isEnabled: true
});
console.log('[X Country Filter] Extension installed with default settings');
}
});
// Handle messages from content script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'updateBadge') {
const count = message.count;
if (count > 0) {
chrome.action.setBadgeText({ text: count.toString(), tabId: sender.tab?.id });
chrome.action.setBadgeBackgroundColor({ color: '#ef4444', tabId: sender.tab?.id });
} else {
chrome.action.setBadgeText({ text: '', tabId: sender.tab?.id });
}
}
if (message.type === 'getSettings') {
chrome.storage.sync.get(['blockedCountries', 'isEnabled'], (result) => {
sendResponse(result);
});
return true; // Keep channel open for async response
}
if (message.type === 'saveSettings') {
chrome.storage.sync.set(message.settings, () => {
sendResponse({ success: true });
});
return true;
}
});
// Clear badge when navigating away from X
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'loading') {
const url = tab.url || '';
if (!url.includes('twitter.com') && !url.includes('x.com')) {
chrome.action.setBadgeText({ text: '', tabId });
}
}
});