-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
38 lines (34 loc) · 868 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
'use strict';
let keyword = '';
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.message) {
case 'get':
sendResponse({ keyword });
break;
case 'setKeyword':
keyword = request.keyword;
break;
case 'tabLoaded':
sendResponse({ keyword });
break;
case 'replaceAll':
return replaceAll();
break;
}
});
function replaceAll() {
new Promise(async resolve => {
let tabList = [];
chrome.windows.getAll({ populate: true }, windows => {
windows.forEach(window => {
window.tabs.forEach(tab => {
tabList.push(tab);
});
});
resolve(tabList);
});
}).then(tabList => {
tabList.forEach(tab => chrome.tabs.sendMessage(tab.id, { message: 'replaceAll', keyword }));
});
return true; // this means its async
}