-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
36 lines (32 loc) · 1004 Bytes
/
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
31
32
33
34
35
36
// Initialize the side panel
chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((error) => console.error(error));
// Listen for navigation to search pages
chrome.webNavigation.onCompleted.addListener(async (details) => {
try {
const url = new URL(details.url);
const searchParams = {
'www.google.com': 'q',
'www.bing.com': 'q',
'duckduckgo.com': 'q',
'search.brave.com': 'q',
'search.yahoo.com': 'p',
'www.baidu.com': 'wd',
'yandex.com': 'text',
'www.ecosia.org': 'q',
'www.qwant.com': 'q',
'www.startpage.com': 'query'
};
const hostname = url.hostname;
const paramName = searchParams[hostname];
if (paramName && url.searchParams.has(paramName)) {
const query = url.searchParams.get(paramName);
if (query) {
await chrome.storage.local.set({ currentQuery: query });
}
}
} catch (error) {
console.error('Error processing URL:', error);
}
});