-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (32 loc) · 1.39 KB
/
background.js
File metadata and controls
38 lines (32 loc) · 1.39 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
// background.js - Implements the main logic of the extension
// Actions to execute when installed
chrome.runtime.onInstalled.addListener(() => {
console.log('GitHub to DeepWiki extension installed');
});
// Add message listener to respond to messages from popup
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'checkGitHub') {
// When receiving a check request, get the current tab URL
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
const currentTab = tabs[0];
const currentUrl = currentTab.url;
// Check if URL starts with https://github.com/
if (currentUrl.startsWith('https://github.com/')) {
// If it's a GitHub URL, convert and redirect directly
const newUrl = currentUrl.replace('https://github.com/', 'https://deepwiki.com/');
chrome.tabs.update(currentTab.id, { url: newUrl });
// Close the message sender (popup) after conversion
if (sender.tab) {
chrome.tabs.remove(sender.tab.id);
}
// Reply to the message, indicating it's a GitHub URL
sendResponse({isGitHub: true});
} else {
// If it's not a GitHub URL, just notify the popup
sendResponse({isGitHub: false});
}
});
// Return true to indicate this message will be processed asynchronously
return true;
}
});