Handling and logging of blocked resources (#1481)

This commit is contained in:
nobody 2023-07-11 19:21:33 +02:00
parent 2bb256418b
commit 8e91bbcb9e
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
3 changed files with 24 additions and 7 deletions

View File

@ -97,6 +97,10 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts);
// Check if the website is allowed to load Google Fonts
if (interceptor.blockGoogleFonts === true && isListed === false) {
console.log(`${LogString.PREFIX} Google fonts blocked ${requestDetails.url}`);
log.append(tab.url, requestDetails.url, '-', true, iframe);
interceptor._handleMissingCandidate(requestDetails.url, tabIdentifier);
++stateManager.tabs[tabIdentifier].blocked;
return {
'redirectUrl': chrome.runtime.getURL('resources/google-fonts-placeholder.css')
};
@ -128,13 +132,14 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
*/
interceptor._handleMissingCandidate = function (requestUrl, tabIdentifier) {
let requestUrlSegments, injectionCount, missingCount;
let requestUrlSegments, injectionCount, missingCount, blockedCount;
if (stateManager.showIconBadge === true) {
injectionCount = Object.keys(stateManager.tabs[tabIdentifier].injections).length || 0;
if (stateManager.changeBadgeColorMissingResources === true) {
missingCount = stateManager.tabs[tabIdentifier].missing || 0;
if (missingCount > 0 && injectionCount === 0) {
blockedCount = stateManager.tabs[tabIdentifier].blocked || 0;
if ((missingCount > 0 || blockedCount > 0) && injectionCount === 0) {
wrappers.setBadgeText(tabIdentifier, injectionCount);
wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE);
}

View File

@ -31,7 +31,8 @@ var stateManager = {};
*/
stateManager.registerInjection = function (tabIdentifier, injection, url) {
let injectionIdentifier, registeredTab, injectionCount, missingCount, initiatorDomain, htmlFilterIsActive;
let injectionIdentifier, registeredTab, injectionCount, missingCount, blockedCount,
initiatorDomain, htmlFilterIsActive;
if (injection['result'] !== false) {
injectionIdentifier = injection.source + injection.path;
@ -42,8 +43,13 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) {
initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE;
htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain);
if (registeredTab !== undefined) {
injectionCount = Object.keys(registeredTab.injections).length || 0;
missingCount = registeredTab.missing || 0;
blockedCount = registeredTab.blocked || 0;
} else {
return;
}
if (injectionCount > 0) {
chrome.browserAction.setTitle({
@ -52,7 +58,7 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) {
});
}
if (stateManager.showIconBadge === true) {
if (missingCount > 0 && stateManager.changeBadgeColorMissingResources) {
if ((missingCount > 0 || blockedCount > 0) && stateManager.changeBadgeColorMissingResources) {
wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE);
} else if (htmlFilterIsActive) {
wrappers.setBadgeColoring(tabIdentifier, BadgeSettingHTMLFilter.TYPE);
@ -156,7 +162,8 @@ stateManager._createTab = function (tab) {
stateManager.tabs[tabIdentifier] = {
'injections': {},
'missing': 0
'missing': 0,
'blocked': 0
};
requestFilters = {
@ -205,6 +212,7 @@ stateManager._updateTab = function (details) {
if (stateManager.tabs[tabIdentifier]) {
stateManager.tabs[tabIdentifier].injections = {};
stateManager.tabs[tabIdentifier].missing = 0;
stateManager.tabs[tabIdentifier].blocked = 0;
}
};

View File

@ -43,6 +43,10 @@
<li>handlebars.js v4.7.7 (<a href="https://codeberg.org/nobody/LocalCDN/issues/1472">#1472</a>)</li>
<li>Swiper v10.0.3 (<a href="https://codeberg.org/nobody/LocalCDN/issues/1479">#1479</a>)</li>
</ul>
<p>Improved</p>
<ul>
<li>Handling and logging of blocked resources (<a href="https://codeberg.org/nobody/LocalCDN/issues/1481">#1481</a>)</li>
</ul>
</div>
<div id="generator-section">
<div class="topic-label">