-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
86 lines (76 loc) · 2.19 KB
/
Copy pathbackground.js
File metadata and controls
86 lines (76 loc) · 2.19 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Store tab states
const tabStates = new Map();
// Default settings
const defaultSettings = {
categories: {
showIDE: true,
showDeepWiki: true,
showDiagram: true,
showGitingest: true
},
ideOptions: {
showVSCode: true,
showGithubDev: true,
showCodeSandbox: true,
showStackBlitz: true,
showGitpod: true
}
};
// Initialize settings when extension is installed or updated
chrome.runtime.onInstalled.addListener((details) => {
console.log('Extension installed/updated:', details.reason);
chrome.storage.sync.get(defaultSettings, (settings) => {
// If settings don't exist or are incomplete, set them to defaults
if (!settings.categories || !settings.ideOptions) {
chrome.storage.sync.set(defaultSettings, () => {
if (chrome.runtime.lastError) {
console.error('Failed to initialize default settings:', chrome.runtime.lastError);
} else {
console.log('Default settings initialized');
}
});
}
});
});
// Listen for tab updates
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url?.includes('github.com')) {
// Reset state for this tab
tabStates.set(tabId, {
buttonsAdded: false,
lastPath: new URL(tab.url).pathname
});
// Notify content script to update buttons
chrome.tabs.sendMessage(tabId, {
type: 'URL_CHANGED',
url: tab.url
}).catch(() => {
// Ignore errors when content script isn't ready yet
});
}
});
// Clean up when tab closes
chrome.tabs.onRemoved.addListener((tabId) => {
tabStates.delete(tabId);
});
// Handle messages from content script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
const tabId = sender.tab?.id;
if (!tabId) return;
switch (message.type) {
case 'GET_STATE':
sendResponse(tabStates.get(tabId) || { buttonsAdded: false });
break;
case 'UPDATE_STATE':
tabStates.set(tabId, {
...tabStates.get(tabId),
...message.state
});
break;
case 'BUTTONS_ADDED':
if (tabStates.has(tabId)) {
tabStates.get(tabId).buttonsAdded = true;
}
break;
}
});