1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-05-19 19:02:21 +02:00

Added "constant" rng.

This commit is contained in:
kkapsner 2017-08-07 17:43:57 +02:00
parent 4cb91462f7
commit 9da251b14d
6 changed files with 49 additions and 4 deletions

View File

@ -133,13 +133,17 @@
}, },
"rng_description": { "rng_description": {
"message": "nicht persistent: die Zufallszahlen werden bei jeder Vortäuschaktion neu bestimmt.\npersistent: für jede Domain werden die Zufallszahlen nur einmal bestimmt.", "message": "nicht persistent: die Zufallszahlen werden bei jeder Vortäuschaktion neu bestimmt.\nkonstant: innerhalb einer Webseite wird eine Farbe immer gleich verändert.\npersistent: für jede Domain werden die Zufallszahlen nur einmal bestimmt.",
"description": "" "description": ""
}, },
"rng_options.persistent": { "rng_options.persistent": {
"message": "persistent", "message": "persistent",
"description": "" "description": ""
}, },
"rng_options.constant": {
"message": "konstant",
"description": ""
},
"rng_options.non persistent": { "rng_options.non persistent": {
"message": "nicht persistent", "message": "nicht persistent",
"description": "" "description": ""

View File

@ -133,13 +133,17 @@
}, },
"rng_description": { "rng_description": {
"message": "non persistent: the random numbers will be determined freshly for each faking action.\npersistent: the random number will only be determined once for every domain.", "message": "non persistent: the random numbers will be determined freshly for each faking action.\nconstant: within one web page a color will always be faked to the same color.\npersistent: the random number will only be determined once for every domain.",
"description": "" "description": ""
}, },
"rng_options.persistent": { "rng_options.persistent": {
"message": "persistent", "message": "persistent",
"description": "" "description": ""
}, },
"rng_options.constant": {
"message": "constant",
"description": ""
},
"rng_options.non persistent": { "rng_options.non persistent": {
"message": "non persistent", "message": "non persistent",
"description": "" "description": ""

View File

@ -7,7 +7,7 @@ var settings = {
blockMode: "fakeReadout", blockMode: "fakeReadout",
minFakeSize: 1, minFakeSize: 1,
maxFakeSize: 0, maxFakeSize: 0,
rng: "nonPersistent", rng: "constant",
persistentRndStorage: "", persistentRndStorage: "",
storePersistentRnd: false, storePersistentRnd: false,
askOnlyOnce: true, askOnlyOnce: true,

View File

@ -25,6 +25,9 @@
case "persistent": case "persistent":
setRandomSupply(randomSupplies.persistent); setRandomSupply(randomSupplies.persistent);
break; break;
case "constant":
setRandomSupply(randomSupplies.constant);
break;
default: default:
setRandomSupply(randomSupplies.nonPersistent); setRandomSupply(randomSupplies.nonPersistent);
} }

View File

@ -87,6 +87,36 @@
} }
}; };
scope.constant = {
getRng: function(length, window){
return scope.nonPersistent.getRng(length, window);
},
getPixelRng: (function(){
var colors = Object.create(null);
return function getConstantPixelRng(length, window, ignoredColors){
var rng = scope.nonPersistent.getRng(1024, window);
return function(r, g, b, a, i){
var index = String.fromCharCode(r, g, b, a);
if (ignoredColors[index]){
return [r, g, b, a];
}
var color = colors[index];
if (!color){
color = [
rng(r, 0),
rng(g, 0),
rng(b, 0),
rng(a, 0)
];
colors[index] = color;
}
return color;
};
};
}())
};
scope.nonPersistent = { scope.nonPersistent = {
getRng: function(length, window){ getRng: function(length, window){
// Initialize the random number batch creation // Initialize the random number batch creation

View File

@ -97,6 +97,10 @@ document.body.appendChild(table);
"value": "nonPersistent", "value": "nonPersistent",
"label": "non persistent" "label": "non persistent"
}, },
{
"value": "constant",
"label": "constant"
},
{ {
"value": "persistent", "value": "persistent",
"label": "persistent" "label": "persistent"