Logging (on/off) added in the settings

This commit is contained in:
nobody42 2020-03-29 10:23:16 +02:00
parent a79062148b
commit b58ef634e0
No known key found for this signature in database
GPG Key ID: AB5145CF05BFE119
6 changed files with 42 additions and 5 deletions

View File

@ -70,5 +70,13 @@
"generateRuleSetTitle": { "generateRuleSetTitle": {
"message": "Generate rule sets for uBlock or uMatrix", "message": "Generate rule sets for uBlock or uMatrix",
"description": "Generate rule set title." "description": "Generate rule set title."
},
"loggingTitle": {
"message": "Enable logging in browser console",
"description": "Enable logging in browser console."
},
"loggingDescription": {
"message": "Open \"Browser Console\" ( CTRL + SHIFT + J ) to show missing resources",
"description": "Generate rule set title."
} }
} }

View File

@ -64,7 +64,8 @@ const Setting = {
'STRIP_METADATA': 'stripMetadata', 'STRIP_METADATA': 'stripMetadata',
'LAST_MAPPING_UPDATE': 'lastMappingUpdate', 'LAST_MAPPING_UPDATE': 'lastMappingUpdate',
'WHITELISTED_DOMAINS': 'whitelistedDomains', 'WHITELISTED_DOMAINS': 'whitelistedDomains',
'XHR_TEST_DOMAIN': 'xhrTestDomain' 'XHR_TEST_DOMAIN': 'xhrTestDomain',
'LOGGING': 'enableLogging'
}; };
const WebRequest = { const WebRequest = {

View File

@ -33,7 +33,8 @@ main._initializeSettings = function () {
[Setting.ENFORCE_STAGING]: false, [Setting.ENFORCE_STAGING]: false,
[Setting.STRIP_METADATA]: true, [Setting.STRIP_METADATA]: true,
[Setting.LAST_MAPPING_UPDATE]: "2020-01-01", [Setting.LAST_MAPPING_UPDATE]: "2020-01-01",
[Setting.WHITELISTED_DOMAINS]: {} [Setting.WHITELISTED_DOMAINS]: {},
[Setting.LOGGING]: false
}; };
chrome.storage.local.get(settingDefaults, function (items) { chrome.storage.local.get(settingDefaults, function (items) {

View File

@ -91,8 +91,11 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
let resourcePath, versionNumber, resourcePattern, filename; let resourcePath, versionNumber, resourcePattern, filename;
resourcePath = channelPath.replace(basePath, ''); chrome.storage.local.get(Setting.LOGGING, function (items) {
requestAnalyzer.logging = items.enableLogging;
});
resourcePath = channelPath.replace(basePath, '');
versionNumber = resourcePath.match(Resource.VERSION_EXPRESSION); versionNumber = resourcePath.match(Resource.VERSION_EXPRESSION);
resourcePattern = resourcePath.replace(versionNumber, Resource.VERSION_PLACEHOLDER); resourcePattern = resourcePath.replace(versionNumber, Resource.VERSION_PLACEHOLDER);
@ -129,7 +132,9 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
targetPath = targetPath + filename + 'm'; targetPath = targetPath + filename + 'm';
} }
console.log('[ LocalCDN ] Replaced resource: ' + targetPath); if (requestAnalyzer.logging) {
console.log('[ LocalCDN ] Replaced resource: ' + targetPath);
}
// Prepare and return a local target. // Prepare and return a local target.
return { return {
'source': channelHost, 'source': channelHost,
@ -139,7 +144,9 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
}; };
} }
} }
console.warn('[ LocalCDN ] Missing resource: ' + channelHost + channelPath); if (requestAnalyzer.logging) {
console.warn('[ LocalCDN ] Missing resource: ' + channelHost + channelPath);
}
return false; return false;
}; };

View File

@ -121,6 +121,23 @@
</section> </section>
<section class="option">
<div class="title-option">
<label class="label-checkbox">
<input class="input-checkbox" data-option="enableLogging" type="checkbox">
<span data-i18n-content="loggingTitle"></span>
</label>
</div>
<div class="description-option" data-i18n-content="loggingDescription"></div>
</section>
<section class="option"> <section class="option">
<div class="title-option" data-i18n-content="whitelistedDomainsTitle"></div> <div class="title-option" data-i18n-content="whitelistedDomainsTitle"></div>

View File

@ -45,6 +45,7 @@ options._renderOptionsPanel = function () {
elements.blockMissing.checked = options._optionValues.blockMissing; elements.blockMissing.checked = options._optionValues.blockMissing;
elements.disablePrefetch.checked = options._optionValues.disablePrefetch; elements.disablePrefetch.checked = options._optionValues.disablePrefetch;
elements.stripMetadata.checked = options._optionValues.stripMetadata; elements.stripMetadata.checked = options._optionValues.stripMetadata;
elements.enableLogging.checked = options._optionValues.enableLogging;
elements.whitelistedDomains.value = domainWhitelist; elements.whitelistedDomains.value = domainWhitelist;
options._registerOptionChangedEventListeners(elements); options._registerOptionChangedEventListeners(elements);
@ -85,6 +86,7 @@ options._registerOptionChangedEventListeners = function (elements) {
elements.blockMissing.addEventListener('change', options._onOptionChanged); elements.blockMissing.addEventListener('change', options._onOptionChanged);
elements.disablePrefetch.addEventListener('change', options._onOptionChanged); elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
elements.stripMetadata.addEventListener('change', options._onOptionChanged); elements.stripMetadata.addEventListener('change', options._onOptionChanged);
elements.enableLogging.addEventListener('change', options._onOptionChanged);
elements.whitelistedDomains.addEventListener('keyup', options._onOptionChanged); elements.whitelistedDomains.addEventListener('keyup', options._onOptionChanged);
let type = elements.ruleSets; let type = elements.ruleSets;
for(let i = 0; i < type.length; i++) { for(let i = 0; i < type.length; i++) {
@ -132,6 +134,7 @@ options._getOptionElements = function () {
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH), [Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA), [Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
[Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS), [Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS),
[Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
['ruleSets']: document.getElementsByName("rule-sets"), ['ruleSets']: document.getElementsByName("rule-sets"),
['copyRuleSet']: document.getElementById("button-copy-rule-set") ['copyRuleSet']: document.getElementById("button-copy-rule-set")
}; };