1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-05-29 09:28:06 +02:00

Added warning if some features of a API are disabled

This commit is contained in:
kkapsner 2020-03-06 12:06:40 +01:00
parent d449e5f0c3
commit 73e5f5737b
3 changed files with 40 additions and 25 deletions

View File

@ -1476,6 +1476,10 @@
"message": "All features of {api} are disabled but the protection is enabled.", "message": "All features of {api} are disabled but the protection is enabled.",
"description": "" "description": ""
}, },
"sanitation_error.disabledSomeFeatures": {
"message": "Some features of {api} are disabled. This should only be done in testing or if you really know what the features are doing.",
"description": ""
},
"sanitation_resolution.disableMainFlag": { "sanitation_resolution.disableMainFlag": {
"message": "disable main flag", "message": "disable main flag",
"description": "" "description": ""

View File

@ -55,9 +55,12 @@
{ {
name: "disabledFeatures", name: "disabledFeatures",
check: function(errorCallback){ check: function(errorCallback){
const errorMessage = extension.getTranslation("sanitation_error.disabledFeatures"); const allErrorMessage = extension.getTranslation("sanitation_error.disabledFeatures");
function createErrorMessage(api){ const someErrorMessage = extension.getTranslation("sanitation_error.disabledSomeFeatures");
return errorMessage.replace(/{api}/g, extension.getTranslation("section_" + api.section)); function createErrorMessage(api, all = false){
return (all? allErrorMessage: someErrorMessage).replace(
/{api}/g,
extension.getTranslation("section_" + api.section));
} }
const protectedFeatures = settings.getDefinition("protectedAPIFeatures"); const protectedFeatures = settings.getDefinition("protectedAPIFeatures");
const protectedFeaturesValue = protectedFeatures.get(); const protectedFeaturesValue = protectedFeatures.get();
@ -84,31 +87,39 @@
{mainFlag: "protectScreen", section: "Screen-API"}, {mainFlag: "protectScreen", section: "Screen-API"},
].forEach(function(api){ ].forEach(function(api){
if (settings.get(api.mainFlag) !== (api.mainFlagDisabledValue || false)){ if (settings.get(api.mainFlag) !== (api.mainFlagDisabledValue || false)){
if (getSectionKeys(api.section).every(function(key){ const sectionKeys = getSectionKeys(api.section);
if (sectionKeys.some(function(key){
return protectedFeaturesValue.hasOwnProperty(key) && return protectedFeaturesValue.hasOwnProperty(key) &&
!protectedFeaturesValue[key]; !protectedFeaturesValue[key];
})){ })){
const all = sectionKeys.every(function(key){
return protectedFeaturesValue.hasOwnProperty(key) &&
!protectedFeaturesValue[key];
});
const resolutions = [
{
label: extension.getTranslation("sanitation_resolution.enableFeatures"),
callback: function(){
const protectedFeaturesValue = protectedFeatures.get();
sectionKeys.forEach(function(key){
protectedFeaturesValue[key] = true;
});
protectedFeatures.set(protectedFeaturesValue);
}
},
];
if (all){
resolutions.push({
label: extension.getTranslation("sanitation_resolution.disableMainFlag"),
callback: function(){
settings.set(api.mainFlag, api.mainFlagDisabledValue || false);
}
});
}
errorCallback({ errorCallback({
message: createErrorMessage(api), message: createErrorMessage(api, all),
severity: "high", severity: all? "high": "medium",
resolutions: [ resolutions
{
label: extension.getTranslation("sanitation_resolution.enableFeatures"),
callback: function(){
const protectedFeaturesValue = protectedFeatures.get();
getSectionKeys(api.section).forEach(function(key){
protectedFeaturesValue[key] = true;
});
protectedFeatures.set(protectedFeaturesValue);
}
},
{
label: extension.getTranslation("sanitation_resolution.disableMainFlag"),
callback: function(){
settings.set(api.mainFlag, api.mainFlagDisabledValue || false);
}
},
]
}); });
} }
} }

View File

@ -4,7 +4,7 @@ Version 1.2:
- always open options page in new tab - always open options page in new tab
new features: new features:
- - added warning if some features of a API are disabled
fixes: fixes:
- -