From b61cd75b25c28b7bb3f815baa89edcfaad385244 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 22 Feb 2021 00:32:22 +0300 Subject: [PATCH] ignore style messages if started in disableAll mode --- content/apply.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/content/apply.js b/content/apply.js index d1f9993e..1df2de43 100644 --- a/content/apply.js +++ b/content/apply.js @@ -6,7 +6,12 @@ (() => { if (window.INJECTED === 1) return; + /** true -> when the page styles are received, + * false -> when disableAll mode is on at start, the styles won't be sent + * so while disableAll lasts we can ignore messages about style updates because + * the tab will explicitly ask for all styles in bulk when disableAll mode ends */ let hasStyles = false; + let isDisabled = false; let isTab = !chrome.tabs || location.pathname !== '/popup.html'; const isFrame = window !== parent; const isFrameAboutBlank = isFrame && location.href === 'about:blank'; @@ -75,7 +80,8 @@ parentStyles && await new Promise(requestAnimationFrame) && parentStyles || !isFrameAboutBlank && chrome.app && !chrome.tabs && tryCatch(getStylesViaXhr) || await API.styles.getSectionsByUrl(matchUrl, null, true); - hasStyles = !styles.disableAll; + isDisabled = styles.disableAll; + hasStyles = !isDisabled; if (hasStyles) { window[SYM] = styles; await styleInjector.apply(styles); @@ -121,6 +127,7 @@ break; case 'styleUpdated': + if (!hasStyles && isDisabled) break; if (style.enabled) { API.styles.getSectionsByUrl(matchUrl, style.id).then(sections => sections[style.id] @@ -132,6 +139,7 @@ break; case 'styleAdded': + if (!hasStyles && isDisabled) break; if (style.enabled) { API.styles.getSectionsByUrl(matchUrl, style.id) .then(styleInjector.apply); @@ -139,6 +147,7 @@ break; case 'urlChanged': + if (!hasStyles && isDisabled) break; API.styles.getSectionsByUrl(matchUrl).then(sections => { hasStyles = true; styleInjector.replace(sections); @@ -159,6 +168,7 @@ } function updateDisableAll(key, disableAll) { + isDisabled = disableAll; if (isUnstylable) { API.styleViaAPI({method: 'prefChanged', prefs: {disableAll}}); } else if (!hasStyles && !disableAll) {