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