Added setting for minimal colors

Fixes #162
This commit is contained in:
kkapsner 2017-12-11 12:47:43 +01:00
parent e128cba84a
commit 096db123d7
7 changed files with 70 additions and 2 deletions

View File

@ -311,6 +311,15 @@
"description": ""
},
"minColors_title": {
"message": "Minimale Anzahl an Farben",
"description": ""
},
"minColors_description": {
"message": "Anzahl der Farben, die ein Canvas aufweisen muss, damit es vorgetäuscht wird. Dies ist ein Parameter, der die Detektion des Addons erschweren soll.\nACHTUNG: Dies kann die Sicherheit des Addons beeinträchtigen. Deswegen wird stark empfohlen, diesen Wert nicht über 10 zu setzen.",
"description": ""
},
"fakeAlphaChannel_title": {
"message": "Alpha-Kanal auch vortäuschen",
"description": ""

View File

@ -311,6 +311,15 @@
"description": ""
},
"minColors_title": {
"message": "Minimal number of colors",
"description": ""
},
"minColors_description": {
"message": "Number of colors that a canvas must have to be faked.\nCAUTION: This can lower the safety of the addon, therefore it is highly recommended not to set this value above 10.",
"description": ""
},
"fakeAlphaChannel_title": {
"message": "Fake the alpha channel",
"description": ""

View File

@ -82,4 +82,29 @@
}
return statistic;
};
scope.hasMoreColors = function hasMoreColors(rawData, threshold, statistic){
if (statistic){
return statistic.numberOfColors > threshold;
}
else {
var colors = Object.create(null);
var count = 0;
for (var i = 0, l = rawData.length; i < l; i += 4){
var index = String.fromCharCode(
rawData[i + 0],
rawData[i + 1],
rawData[i + 2],
rawData[i + 3]
);
if (!Object.prototype.hasOwnProperty.call(colors, index)){
colors[index] = true;
count += 1;
if (count > threshold){
return true;
}
}
}
return count > threshold;
}
};
}());

View File

@ -79,10 +79,16 @@
var l = desc.length;
var ignoredColors = {};
var statistic;
if (prefs("ignoreFrequentColors")){
var statistic = colorStatistics.compute(source);
statistic = colorStatistics.compute(source);
ignoredColors = statistic.getMaxColors(prefs("ignoreFrequentColors"));
}
if (prefs("minColors")){
if (!colorStatistics.hasMoreColors(source, prefs("minColors"), statistic)){
return original;
}
}
var rng = randomSupply.getPixelRng(l, window, ignoredColors);
var fakeAlphaChannel = prefs("fakeAlphaChannel");

View File

@ -67,6 +67,10 @@
name: "ignoreFrequentColors",
defaultValue: 0
},
{
name: "minColors",
defaultValue: 0
},
{
name: "fakeAlphaChannel",
defaultValue: false

View File

@ -143,6 +143,20 @@
}
]
},
{
"name": "minColors",
"displayDependencies": [
{
"blockMode": ["fakeReadout"],
"displayAdvancedSettings": [true]
},
{
"blockMode": ["askReadout", "ask"],
"askDenyMode": ["fake"],
"displayAdvancedSettings": [true]
}
]
},
{
"name": "fakeAlphaChannel",
"displayDependencies": [

View File

@ -8,7 +8,8 @@ Version 0.4.3:
new features:
- reset settings
- new white random generator - creates output similar to Tor browser
- blockMode and showNotifications can now be chosen url specific
- blockMode and showNotifications can now be chosen url specific
- new setting to ignore canvas with only few colors
fixes:
- page action was not always showing