refreshAllTabs: process all frames
This commit is contained in:
parent
36fcb02b51
commit
9c1c15465e
|
@ -276,38 +276,39 @@ function importFromString(jsonString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshAllTabs() {
|
function refreshAllTabs() {
|
||||||
return Promise.all([
|
return getOwnTab().then(ownTab => new Promise(resolve => {
|
||||||
getActiveTab(),
|
|
||||||
getOwnTab(),
|
|
||||||
]).then(([activeTab, ownTab]) => new Promise(resolve => {
|
|
||||||
// list all tabs including chrome-extension:// which can be ours
|
|
||||||
queryTabs().then(tabs => {
|
queryTabs().then(tabs => {
|
||||||
const lastTab = tabs[tabs.length - 1];
|
tabs = !FIREFOX ? tabs : tabs.filter(tab => tab.width);
|
||||||
for (const tab of tabs) {
|
tabs.forEach((tab, i) =>
|
||||||
// skip lazy-loaded aka unloaded tabs that seem to start loading on message in FF
|
refreshTab(tab, ownTab, (i === tabs.length - 1) && resolve));
|
||||||
if (FIREFOX && !tab.width) {
|
if (!tabs.length) {
|
||||||
if (tab === lastTab) {
|
resolve();
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
getStylesSafe({matchUrl: tab.url, enabled: true, asHash: true}).then(styles => {
|
|
||||||
const message = {method: 'styleReplaceAll', styles};
|
|
||||||
if (tab.id === ownTab.id) {
|
|
||||||
applyOnMessage(message);
|
|
||||||
} else {
|
|
||||||
message.tabId = tab.id;
|
|
||||||
invokeOrPostpone(tab.id === activeTab.id, sendMessage, message, ignoreChromeError);
|
|
||||||
}
|
|
||||||
setTimeout(BG.updateIcon, 0, tab, styles);
|
|
||||||
if (tab === lastTab) {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshTab(tab, ownTab, resolve) {
|
||||||
|
const tabId = tab.id;
|
||||||
|
chrome.webNavigation.getAllFrames({tabId}, frames => {
|
||||||
|
(frames || []).forEach(({frameId}) =>
|
||||||
|
getStylesSafe({matchUrl: tab.url, enabled: true, asHash: true}).then(styles => {
|
||||||
|
const message = {method: 'styleReplaceAll', tabId, frameId, styles};
|
||||||
|
if (tab.id === ownTab.id) {
|
||||||
|
applyOnMessage(message);
|
||||||
|
} else {
|
||||||
|
invokeOrPostpone(tab.active, sendMessage, message, ignoreChromeError);
|
||||||
|
}
|
||||||
|
if (frameId === 0) {
|
||||||
|
setTimeout(BG.updateIcon, 0, tab, styles);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
if (resolve) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
ignoreChromeError();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,18 +111,22 @@ var hotkeys = (() => {
|
||||||
function refreshAllTabs() {
|
function refreshAllTabs() {
|
||||||
getStylesSafe({matchUrl: location.href, enabled: true, asHash: true})
|
getStylesSafe({matchUrl: location.href, enabled: true, asHash: true})
|
||||||
.then(styles => applyOnMessage({method: 'styleReplaceAll', styles}));
|
.then(styles => applyOnMessage({method: 'styleReplaceAll', styles}));
|
||||||
queryTabs().then(tabs => {
|
queryTabs().then(tabs =>
|
||||||
for (const tab of tabs) {
|
tabs.forEach(tab => (!FIREFOX || tab.width) &&
|
||||||
// skip lazy-loaded aka unloaded tabs that seem to start loading on message in FF
|
refreshTab(tab)));
|
||||||
if (!FIREFOX || tab.width) {
|
}
|
||||||
getStylesSafe({matchUrl: tab.url, enabled: true, asHash: true}).then(styles => {
|
|
||||||
const message = {method: 'styleReplaceAll', styles, tabId: tab.id};
|
function refreshTab(tab) {
|
||||||
invokeOrPostpone(tab.active, sendMessage, message, ignoreChromeError);
|
const tabId = tab.id;
|
||||||
|
chrome.webNavigation.getAllFrames({tabId}, frames => !frames && ignoreChromeError() ||
|
||||||
|
frames.forEach(({frameId}) =>
|
||||||
|
getStylesSafe({matchUrl: tab.url, enabled: true, asHash: true}).then(styles => {
|
||||||
|
const message = {method: 'styleReplaceAll', tabId, frameId, styles};
|
||||||
|
invokeOrPostpone(tab.active, sendMessage, message, ignoreChromeError);
|
||||||
|
if (frameId === 0) {
|
||||||
setTimeout(BG.updateIcon, 0, tab, styles);
|
setTimeout(BG.updateIcon, 0, tab, styles);
|
||||||
});
|
}
|
||||||
}
|
})));
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initHotkeyInfo() {
|
function initHotkeyInfo() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user