mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
308d7c4005
commit
49f3c166a2
2 changed files with 73 additions and 10 deletions
|
@ -2,6 +2,7 @@
|
|||
"use strict";
|
||||
|
||||
const values = {};
|
||||
let nestedValues = false;
|
||||
const navigator = self.navigator;
|
||||
Object.keys(navigator.__proto__).sort().forEach(function(property){
|
||||
const value = navigator[property];
|
||||
|
@ -9,16 +10,49 @@
|
|||
values[property] = value;
|
||||
}
|
||||
});
|
||||
if (self.postMessage){
|
||||
self.postMessage(values);
|
||||
|
||||
const ports = [];
|
||||
const sources = [];
|
||||
let sendDelayed = false;
|
||||
function sendData(){
|
||||
sendDelayed = true;
|
||||
if (self.postMessage){
|
||||
self.postMessage({values, nestedValues});
|
||||
}
|
||||
ports.forEach(function(port){
|
||||
port.postMessage({values, nestedValues});
|
||||
});
|
||||
sources.forEach(function(source){
|
||||
source.postMessage({values, nestedValues});
|
||||
});
|
||||
}
|
||||
self.addEventListener("connect", function(event){
|
||||
event.ports.forEach(function(port){
|
||||
port.postMessage(values);
|
||||
ports.push(port);
|
||||
});
|
||||
if (sendDelayed){
|
||||
sendData();
|
||||
}
|
||||
});
|
||||
self.addEventListener("message", function(event){
|
||||
event.source.postMessage(values);
|
||||
return values;
|
||||
sources.push(event.source);
|
||||
if (sendDelayed){
|
||||
sendData();
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
!(self.name && self.name.startsWith("nested nested")) &&
|
||||
self.Worker
|
||||
){
|
||||
const worker = new Worker(self.location, {name: "nested " + (self.name || "")});
|
||||
worker.addEventListener("message", function(event){
|
||||
nestedValues = event.data;
|
||||
worker.terminate();
|
||||
sendData();
|
||||
});
|
||||
}
|
||||
else {
|
||||
sendData();
|
||||
}
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue