1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2024-12-23 00:25:15 +01:00

Check HTML filter improved

This commit is contained in:
nobody 2022-07-10 07:10:26 +02:00
parent 1be3c1cf6d
commit 47d2956824
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
2 changed files with 21 additions and 13 deletions

View File

@ -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
*/

View File

@ -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);