diff --git a/core/manipulate-dom.js b/core/manipulate-dom.js index 16587457..870cc650 100644 --- a/core/manipulate-dom.js +++ b/core/manipulate-dom.js @@ -36,22 +36,14 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) { return; } if (details.statusCode === 200) { - let initiatorDomain, listedToManipulateDOM, negateHtmlFilter, filtering, header; + let initiatorDomain, header; initiatorDomain = helpers.extractDomainFromUrl(details.url, true) || Address.EXAMPLE; - listedToManipulateDOM = stateManager._domainIsListed(initiatorDomain, 'manipulate-dom'); - negateHtmlFilter = stateManager.getInvertOption; - - if ((negateHtmlFilter || listedToManipulateDOM) && !(negateHtmlFilter && listedToManipulateDOM)) { - filtering = true; - } else { - filtering = false; - } // by Jaap (https://gitlab.com/Jaaap) header = details.responseHeaders.find((h) => h.name.toLowerCase() === 'content-type'); - if (header && filtering) { + if (header && manipulateDOM.checkHtmlFilterEnabled(initiatorDomain)) { let mimeType, isAllowlisted; @@ -151,6 +143,22 @@ manipulateDOM._searchCharset = function (str, charset) { return str; }; + +/** + * Public Methods + */ + +manipulateDOM.checkHtmlFilterEnabled = function (url) { + let listedToManipulateDOM, negateHtmlFilter; + listedToManipulateDOM = stateManager._domainIsListed(url, 'manipulate-dom'); + negateHtmlFilter = stateManager.getInvertOption; + + if ((negateHtmlFilter || listedToManipulateDOM) && !(negateHtmlFilter && listedToManipulateDOM)) { + return true; + } + return false; +}; + /** * Initializations */ diff --git a/core/state-manager.js b/core/state-manager.js index 91c9a2ec..10fbe903 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -31,7 +31,7 @@ var stateManager = {}; */ stateManager.registerInjection = function (tabIdentifier, injection, url) { - let injectionIdentifier, registeredTab, injectionCount, missingCount, initiatorDomain, listedToManipulateDOM; + let injectionIdentifier, registeredTab, injectionCount, missingCount, initiatorDomain, htmlFilterIsActive; if (injection['result'] !== false) { injectionIdentifier = injection.source + injection.path; @@ -40,7 +40,7 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) { } initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE; - listedToManipulateDOM = stateManager._domainIsListed(initiatorDomain, 'manipulate-dom'); + htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain); injectionCount = Object.keys(registeredTab.injections).length || 0; missingCount = registeredTab.missing || 0; @@ -54,7 +54,7 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) { if (stateManager.showIconBadge === true) { if (missingCount > 0 && stateManager.changeBadgeColorMissingResources) { wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE); - } else if (listedToManipulateDOM) { + } else if (htmlFilterIsActive) { wrappers.setBadgeColoring(tabIdentifier, BadgeSettingHTMLFilter.TYPE); } else { wrappers.setBadgeColoring(tabIdentifier, BadgeSetting.TYPE);