mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Completely remove function monitoring for white listed sites.
Fixes #84.
This commit is contained in:
parent
bda00e5741
commit
fc07961c6b
102
lib/intercept.js
102
lib/intercept.js
@ -23,59 +23,61 @@
|
||||
exports.setRandomSupplyByType = setRandomSupplyByType;
|
||||
exports.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){
|
||||
var siteStatus = check({url: window.location.href});
|
||||
apiNames.forEach(function(name){
|
||||
var changedFunction = changedFunctions[name];
|
||||
var original = window.wrappedJSObject[changedFunction.object].prototype[name];
|
||||
|
||||
if (changedFunction.getStatus(undefined, siteStatus).active){
|
||||
Object.defineProperty(
|
||||
window.wrappedJSObject[changedFunction.object].prototype,
|
||||
name,
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: function(){
|
||||
if (!window.location.href){
|
||||
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});
|
||||
if (siteStatus.mode !== "allow"){
|
||||
apiNames.forEach(function(name){
|
||||
var changedFunction = changedFunctions[name];
|
||||
var original = window.wrappedJSObject[changedFunction.object].prototype[name];
|
||||
|
||||
if (changedFunction.getStatus(undefined, siteStatus).active){
|
||||
Object.defineProperty(
|
||||
window.wrappedJSObject[changedFunction.object].prototype,
|
||||
name,
|
||||
{
|
||||
enumerable: true,
|
||||
configureable: false,
|
||||
get: function(){
|
||||
if (!window.location.href){
|
||||
return undef;
|
||||
}
|
||||
switch (funcStatus.mode){
|
||||
case "allow":
|
||||
return original;
|
||||
case "fake":
|
||||
setRandomSupplyByType(prefs("rng"));
|
||||
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
||||
notify({url: window.location.href, errorStack: error.stack, messageId});
|
||||
});
|
||||
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: window.location.href, errorStack: error.stack, messageId});
|
||||
});
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}());
|
@ -94,6 +94,7 @@
|
||||
};
|
||||
}
|
||||
else {
|
||||
var status = Object.create(status);
|
||||
status.active = false;
|
||||
return status;
|
||||
}
|
||||
@ -109,6 +110,7 @@
|
||||
},
|
||||
toDataURL: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
if (hasType(status, "input")){
|
||||
var contextType = canvasContextType.get(obj);
|
||||
status.active = contextType !== "2d";
|
||||
@ -129,6 +131,7 @@
|
||||
},
|
||||
toBlob: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
if (hasType(status, "input")){
|
||||
var contextType = canvasContextType.get(obj);
|
||||
status.active = contextType !== "2d";
|
||||
@ -150,6 +153,7 @@
|
||||
},
|
||||
mozGetAsFile: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
if (hasType(status, "input")){
|
||||
var contextType = canvasContextType.get(obj);
|
||||
status.active = contextType !== "2d";
|
||||
@ -170,6 +174,7 @@
|
||||
},
|
||||
getImageData: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
if (hasType(status, "input")){
|
||||
var contextType = canvasContextType.get(obj);
|
||||
status.active = contextType !== "2d";
|
||||
@ -207,6 +212,7 @@
|
||||
},
|
||||
fillText: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
status.active = hasType(status, "input");
|
||||
return status;
|
||||
},
|
||||
@ -225,6 +231,7 @@
|
||||
},
|
||||
strokeText: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
status.active = hasType(status, "input");
|
||||
return status;
|
||||
},
|
||||
@ -243,6 +250,7 @@
|
||||
},
|
||||
readPixels: {
|
||||
getStatus: function(obj, status){
|
||||
var status = Object.create(status);
|
||||
status.active = hasType(status, "readout") || hasType(status, "input");
|
||||
return status;
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user