code cosmetics: add invokeOrPostpone()
This commit is contained in:
parent
1c1a9f2804
commit
358e8e034f
|
@ -38,6 +38,7 @@ globals:
|
||||||
sessionStorageHash: false
|
sessionStorageHash: false
|
||||||
download: false
|
download: false
|
||||||
doTimeout: false
|
doTimeout: false
|
||||||
|
invokeOrPostpone: false
|
||||||
# localization.js
|
# localization.js
|
||||||
template: false
|
template: false
|
||||||
t: false
|
t: false
|
||||||
|
|
|
@ -287,10 +287,9 @@ function importFromString(jsonString) {
|
||||||
const message = {method: 'styleReplaceAll', styles};
|
const message = {method: 'styleReplaceAll', styles};
|
||||||
if (tab.id == ownTab.id) {
|
if (tab.id == ownTab.id) {
|
||||||
applyOnMessage(message);
|
applyOnMessage(message);
|
||||||
} else if (tab.id == activeTab.id) {
|
|
||||||
chrome.tabs.sendMessage(tab.id, message, ignoreChromeError);
|
|
||||||
} else {
|
} else {
|
||||||
setTimeout(chrome.tabs.sendMessage, 0, tab.id, message, ignoreChromeError);
|
invokeOrPostpone(tab.id == activeTab.id,
|
||||||
|
chrome.tabs.sendMessage, tab.id, message, ignoreChromeError);
|
||||||
}
|
}
|
||||||
setTimeout(BG.updateIcon, 0, tab, styles);
|
setTimeout(BG.updateIcon, 0, tab, styles);
|
||||||
if (tab == lastTab) {
|
if (tab == lastTab) {
|
||||||
|
|
13
messaging.js
13
messaging.js
|
@ -81,11 +81,7 @@ function notifyAllTabs(msg) {
|
||||||
]).then(([tabs, activeTab]) => {
|
]).then(([tabs, activeTab]) => {
|
||||||
const activeTabId = activeTab && activeTab.id;
|
const activeTabId = activeTab && activeTab.id;
|
||||||
for (const tab of tabs) {
|
for (const tab of tabs) {
|
||||||
if (tab.id === activeTabId) {
|
invokeOrPostpone(tab.id === activeTabId, notifyTab, tab);
|
||||||
notifyTab(tab);
|
|
||||||
} else {
|
|
||||||
setTimeout(notifyTab, 0, tab);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -366,3 +362,10 @@ function doTimeout(ms = 0, ...args) {
|
||||||
? () => new Promise(resolve => setTimeout(resolve, ms, ...args))
|
? () => new Promise(resolve => setTimeout(resolve, ms, ...args))
|
||||||
: new Promise(resolve => setTimeout(resolve, 0, ...args));
|
: new Promise(resolve => setTimeout(resolve, 0, ...args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function invokeOrPostpone(isInvoke, fn, ...args) {
|
||||||
|
return isInvoke
|
||||||
|
? fn(...args)
|
||||||
|
: setTimeout(invokeOrPostpone, 0, true, fn, ...args);
|
||||||
|
}
|
||||||
|
|
6
popup.js
6
popup.js
|
@ -246,11 +246,7 @@ function createStyleElement({
|
||||||
$('.disable', entry).onclick = handleEvent.toggle;
|
$('.disable', entry).onclick = handleEvent.toggle;
|
||||||
$('.delete', entry).onclick = handleEvent.delete;
|
$('.delete', entry).onclick = handleEvent.delete;
|
||||||
|
|
||||||
if (postponeDetect) {
|
invokeOrPostpone(!postponeDetect, detectSloppyRegexps, {entry, style});
|
||||||
setTimeout(detectSloppyRegexps, 0, {entry, style});
|
|
||||||
} else {
|
|
||||||
detectSloppyRegexps({entry, style});
|
|
||||||
}
|
|
||||||
|
|
||||||
const oldElement = $('#style-' + style.id);
|
const oldElement = $('#style-' + style.id);
|
||||||
if (oldElement) {
|
if (oldElement) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user