mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 03:56:26 +02:00
Added preference to control rng type.
This commit is contained in:
parent
447ff54222
commit
1b2c4cb487
9 changed files with 233 additions and 126 deletions
|
@ -1,20 +1,13 @@
|
|||
/* jslint moz: true, bitwise: true */
|
||||
/* jslint moz: true */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
const rnd = {};
|
||||
var randomSupply = null;
|
||||
|
||||
function getFakeCanvas(window, original){
|
||||
var domain = window.document.location.host;
|
||||
if (!rnd[domain]){
|
||||
rnd[domain] = new Uint8Array(128);
|
||||
for (var i = 0; i < rnd[domain].length; i += 1){
|
||||
rnd[domain][i] = Math.floor(Math.random() * 0xFF);
|
||||
}
|
||||
console.log("created new rnd for domain", domain);
|
||||
}
|
||||
var context = window.HTMLCanvasElement.prototype.getContext.call(original, "2d");
|
||||
var imageData, data, source;
|
||||
if (context){
|
||||
|
@ -38,14 +31,10 @@
|
|||
}
|
||||
data = imageData.data;
|
||||
var l = data.length;
|
||||
var rng = randomSupply.getRng(l, window);
|
||||
|
||||
for (var i = 0; i < l; i += 1){
|
||||
var value = source[i];
|
||||
var index = value & 0x7F;
|
||||
var bitIndex = ((i & 0x03) << 1) | (value >>> 7);
|
||||
var bit = (rnd[domain][index] >>> bitIndex) & 0x01;
|
||||
if (bitIndex % 2) console.log(rnd[domain][index], index, bitIndex, bit);
|
||||
data[i] = value ^ bit;
|
||||
data[i] = rng(source[i], i);
|
||||
}
|
||||
var canvas = original.cloneNode(true);
|
||||
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||
|
@ -55,6 +44,10 @@
|
|||
function getWindow(canvas){
|
||||
return canvas.ownerDocument.defaultView;
|
||||
}
|
||||
|
||||
exports.setRandomSupply = function(supply){
|
||||
randomSupply = supply;
|
||||
};
|
||||
// changed functions and their fakes
|
||||
exports.changedFunctions = {
|
||||
getContext: {
|
||||
|
@ -111,7 +104,7 @@
|
|||
imageData.data[i] = data[i];
|
||||
}
|
||||
return imageData;
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
readPixels: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue