-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (28 loc) · 861 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
37
chrome.runtime.onMessage.addListener(reciever);
function reciever(request){
console.log(request);
var url;
if(request.searchbar==="youtube"){
url=`https://www.youtube.com/results?search_query=+${request.text}`;
}
else{
url=`https://www.google.com/search?q=${request.text}`;
}
console.log(url);
main(url);
function chromeTabsCreateAsync(createProperties) {
return new Promise((resolve, reject) => {
chrome.tabs.create(createProperties, tab => {
if (chrome.runtime.lastError) {
reject(new Error(chrome.runtime.lastError));
} else {
resolve(tab);
}
});
});
}
async function main(searchurl) {
let tab = await chromeTabsCreateAsync({ url: searchurl, active: true});
console.log('Tab created: ' + tab.id);
}
}