1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-05-29 09:28:06 +02:00

Only interfecpt constructors that are present.

Fixes #108.
This commit is contained in:
kkapsner 2017-02-22 17:46:17 +01:00
parent a8611230b1
commit f85303065c

View File

@ -41,56 +41,59 @@
var changedFunction = changedFunctions[name];
if (changedFunction.getStatus(undefined, siteStatus).active){
(Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){
var original = window.wrappedJSObject[object].prototype[name];
Object.defineProperty(
window.wrappedJSObject[object].prototype,
name,
{
enumerable: true,
configureable: false,
get: function(){
var url = getURL(window);
if (!url){
return undef;
}
var error = new Error();
if (checkStack(error.stack)){
return original;
}
var funcStatus = changedFunction.getStatus(this, siteStatus);
if (funcStatus.active){
if (funcStatus.mode === "ask"){
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
var constructor = window.wrappedJSObject[object];
if (constructor){
var original = constructor.prototype[name];
Object.defineProperty(
constructor.prototype,
name,
{
enumerable: true,
configureable: false,
get: function(){
var url = getURL(window);
if (!url){
return undef;
}
switch (funcStatus.mode){
case "allow":
return original;
case "fake":
setRandomSupplyByType(prefs("rng"));
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url, errorStack: error.stack, messageId});
}, original);
switch (fake){
case true:
return original;
case false:
return undef;
default:
return exportFunction(fake, window.wrappedJSObject);
}
//case "block":
default:
return undef;
var error = new Error();
if (checkStack(error.stack)){
return original;
}
var funcStatus = changedFunction.getStatus(this, siteStatus);
if (funcStatus.active){
if (funcStatus.mode === "ask"){
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
}
switch (funcStatus.mode){
case "allow":
return original;
case "fake":
setRandomSupplyByType(prefs("rng"));
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url, errorStack: error.stack, messageId});
}, original);
switch (fake){
case true:
return original;
case false:
return undef;
default:
return exportFunction(fake, window.wrappedJSObject);
}
//case "block":
default:
return undef;
}
}
else {
return original;
}
}
else {
return original;
}
}
}
);
);
}
});
}
});