-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbackground.js
More file actions
47 lines (39 loc) · 1.43 KB
/
Copy pathbackground.js
File metadata and controls
47 lines (39 loc) · 1.43 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
// AiMaster background service worker
console.log('AiMaster background service worker loaded');
// Install or update event
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
console.log('AiMaster installed');
// Set default configuration
chrome.storage.local.set({
apiBaseUrl: 'https://aimedia.daniu7.cn'
});
} else if (details.reason === 'update') {
console.log('AiMaster updated');
}
});
// Listen for messages from popup or content scripts
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log('Received message:', request);
// Handle different message types
switch (request.action) {
case 'log':
console.log('[Content Script]:', request.message);
sendResponse({ success: true });
break;
case 'error':
console.error('[Content Script Error]:', request.message);
sendResponse({ success: true });
break;
default:
console.log('Unknown action:', request.action);
sendResponse({ success: false, error: 'Unknown action' });
}
return true; // Keep message channel open for async response
});
// Handle tab updates
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url) {
console.log('Page loaded:', tab.url);
}
});