1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-04-18 08:08:28 +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]; var changedFunction = changedFunctions[name];
if (changedFunction.getStatus(undefined, siteStatus).active){ if (changedFunction.getStatus(undefined, siteStatus).active){
(Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){ (Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){
var original = window.wrappedJSObject[object].prototype[name]; var constructor = window.wrappedJSObject[object];
if (constructor){
Object.defineProperty( var original = constructor.prototype[name];
window.wrappedJSObject[object].prototype,
name, Object.defineProperty(
{ constructor.prototype,
enumerable: true, name,
configureable: false, {
get: function(){ enumerable: true,
var url = getURL(window); configureable: false,
if (!url){ get: function(){
return undef; var url = getURL(window);
} if (!url){
var error = new Error(); return undef;
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){ var error = new Error();
case "allow": if (checkStack(error.stack)){
return original; return original;
case "fake": }
setRandomSupplyByType(prefs("rng")); var funcStatus = changedFunction.getStatus(this, siteStatus);
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
notify({url, errorStack: error.stack, messageId}); if (funcStatus.active){
}, original); if (funcStatus.mode === "ask"){
switch (fake){ funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
case true: }
return original; switch (funcStatus.mode){
case false: case "allow":
return undef; return original;
default: case "fake":
return exportFunction(fake, window.wrappedJSObject); setRandomSupplyByType(prefs("rng"));
} var fake = changedFunction.fakeGenerator(prefs, function(messageId){
//case "block": notify({url, errorStack: error.stack, messageId});
default: }, original);
return undef; 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;
} }
} }
} );
); }
}); });
} }
}); });