mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 12:06:31 +02:00
parent
3b14e56537
commit
a8611230b1
7 changed files with 99 additions and 8 deletions
39
lib/main.js
39
lib/main.js
|
@ -39,18 +39,49 @@
|
|||
});
|
||||
|
||||
// persistent rng
|
||||
const persistentRnd = Object.create(null);
|
||||
var persistentRnd = Object.create(null);
|
||||
try {
|
||||
let storedData = JSON.parse(prefs.persistentRndStorage);
|
||||
for (var domain in storedData){
|
||||
var value = storedData[domain];
|
||||
if (
|
||||
Array.isArray(value) &&
|
||||
value.length === 128 &&
|
||||
value.every(function(value){return typeof value === "number" && value >= 0 && value < 256;})
|
||||
){
|
||||
persistentRnd[domain] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e){}
|
||||
|
||||
processes.port.on("canvasBlocker-new-domain-rnd", function(process, data){
|
||||
processes.port.emit("canvasBlocker-set-domain-rnd", data);
|
||||
persistentRnd[data.domain] = data.rnd;
|
||||
if (prefs.storePersistentRnd){
|
||||
prefs.persistentRndStorage = JSON.stringify(persistentRnd);
|
||||
}
|
||||
});
|
||||
processes.on("attach", function(process){
|
||||
processes.forEvery(function(process){
|
||||
if (process.isRemote){
|
||||
for (var name in persistentRnd){
|
||||
process.port.emit("canvasBlocker-set-domain-rnd", {domain: name, rnd: persistentRnd[name]});
|
||||
for (var domain in persistentRnd){
|
||||
process.port.emit("canvasBlocker-set-domain-rnd", {domain, rnd: persistentRnd[domain]});
|
||||
}
|
||||
}
|
||||
});
|
||||
preferences.on("storePersistentRnd", function(){
|
||||
if (prefs.storePersistentRnd){
|
||||
prefs.persistentRndStorage = JSON.stringify(persistentRnd);
|
||||
}
|
||||
else {
|
||||
prefs.persistentRndStorage = "";
|
||||
}
|
||||
});
|
||||
preferences.on("clearPersistentRnd", function(){
|
||||
persistentRnd = Object.create(null);
|
||||
prefs.persistentRndStorage = "";
|
||||
processes.port.emit("canvasBlocker-clear-domain-rnd");
|
||||
});
|
||||
|
||||
// show release notes
|
||||
var data = require("sdk/self").data;
|
||||
|
|
|
@ -17,19 +17,23 @@
|
|||
return window.location.host;
|
||||
}
|
||||
const getPersistentRnd = (function(){
|
||||
var persistentRnd = Object.create(null);
|
||||
|
||||
const {process} = require("sdk/remote/child");
|
||||
process.port.on("canvasBlocker-set-domain-rnd", function(process, {domain, rnd}){
|
||||
persistentRnd[domain] = new Uint8Array(rnd);
|
||||
});
|
||||
process.port.on("canvasBlocker-clear-domain-rnd", function(){
|
||||
persistentRnd = Object.create(null);
|
||||
});
|
||||
|
||||
const persistentRnd = Object.create(null);
|
||||
return function getPersistentRnd(window){
|
||||
var domain = getDomain(window);
|
||||
if (!persistentRnd[domain]){
|
||||
// create the (sub-)domains random numbers if not existing
|
||||
persistentRnd[domain] = new Uint8Array(128);
|
||||
window.crypto.getRandomValues(persistentRnd[domain]);
|
||||
process.port.emit("canvasBlocker-new-domain-rnd", {domain, rnd: persistentRnd[domain]});
|
||||
process.port.emit("canvasBlocker-new-domain-rnd", {domain, rnd: Array.from(persistentRnd[domain])});
|
||||
}
|
||||
return persistentRnd[domain];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue