Use chrome.tabs.query instead of 2-tier window+tabs
This commit is contained in:
parent
59e0f3f45e
commit
31a24717b4
21
messaging.js
21
messaging.js
|
@ -3,15 +3,14 @@ const KEEP_CHANNEL_OPEN = true;
|
||||||
const OWN_ORIGIN = chrome.runtime.getURL('');
|
const OWN_ORIGIN = chrome.runtime.getURL('');
|
||||||
|
|
||||||
function notifyAllTabs(request) {
|
function notifyAllTabs(request) {
|
||||||
chrome.windows.getAll({populate: true}, windows => {
|
// list all tabs including chrome-extension:// which can be ours
|
||||||
windows.forEach(win => {
|
chrome.tabs.query({}, tabs => {
|
||||||
win.tabs.forEach(tab => {
|
for (let tab of tabs) {
|
||||||
if (request.codeIsUpdated !== false || tab.url.startsWith(OWN_ORIGIN)) {
|
if (request.codeIsUpdated !== false || tab.url.startsWith(OWN_ORIGIN)) {
|
||||||
chrome.tabs.sendMessage(tab.id, request);
|
chrome.tabs.sendMessage(tab.id, request);
|
||||||
updateIcon(tab);
|
updateIcon(tab);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
// notify all open popups
|
// notify all open popups
|
||||||
const reqPopup = Object.assign({}, request, {method: 'updatePopup', reason: request.method});
|
const reqPopup = Object.assign({}, request, {method: 'updatePopup', reason: request.method});
|
||||||
|
@ -24,9 +23,10 @@ function notifyAllTabs(request) {
|
||||||
|
|
||||||
function refreshAllTabs() {
|
function refreshAllTabs() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
chrome.windows.getAll({populate: true}, windows => {
|
// list all tabs including chrome-extension:// which can be ours
|
||||||
windows.forEach((win, winIndex) => {
|
chrome.tabs.query({}, tabs => {
|
||||||
win.tabs.forEach((tab, tabIndex) => {
|
const lastTab = tabs[tabs.length - 1];
|
||||||
|
for (let tab of tabs) {
|
||||||
getStyles({matchUrl: tab.url, enabled: true, asHash: true}, styles => {
|
getStyles({matchUrl: tab.url, enabled: true, asHash: true}, styles => {
|
||||||
const message = {method: 'styleReplaceAll', styles};
|
const message = {method: 'styleReplaceAll', styles};
|
||||||
if (tab.url == location.href && typeof applyOnMessage !== 'undefined') {
|
if (tab.url == location.href && typeof applyOnMessage !== 'undefined') {
|
||||||
|
@ -35,12 +35,11 @@ function refreshAllTabs() {
|
||||||
chrome.tabs.sendMessage(tab.id, message);
|
chrome.tabs.sendMessage(tab.id, message);
|
||||||
}
|
}
|
||||||
updateIcon(tab, styles);
|
updateIcon(tab, styles);
|
||||||
if (winIndex == windows.length - 1 && tabIndex == win.tabs.length - 1) {
|
if (tab == lastTab) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user