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

Monitoring only the necessary functions -> changes of the mode or the white/black lists only affects new loaded pages.

Fixes #84.
This commit is contained in:
kkapsner 2016-11-13 15:09:03 +01:00
parent b2823cbd8d
commit 82bb25d0f2
2 changed files with 51 additions and 46 deletions

View File

@ -21,56 +21,61 @@
}
}
exports.setRandomSupplyByType = setRandomSupplyByType;
exports.intercept = function intercept({subject: window}, {check, ask, notify, prefs}){
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];
Object.defineProperty(
window.wrappedJSObject[changedFunction.object].prototype,
name,
{
enumerable: true,
configureable: false,
get: function(){
if (!window.location.href){
return undef;
}
var error = new Error();
var status = check({url: window.location.href, errorStack: error.stack});
var funcStatus = changedFunction.getStatus(this, status);
if (funcStatus.active){
if (funcStatus.mode === "ask"){
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
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;
}
}
}
);
);
}
});
};
}());

View File

@ -111,7 +111,7 @@
getStatus: function(obj, status){
if (hasType(status, "input")){
var contextType = canvasContextType.get(obj);
status.active = contextType && contextType !== "2d";
status.active = contextType !== "2d";
}
else {
status.active = hasType(status, "readout");
@ -131,7 +131,7 @@
getStatus: function(obj, status){
if (hasType(status, "input")){
var contextType = canvasContextType.get(obj);
status.active = contextType && contextType !== "2d";
status.active = contextType !== "2d";
}
else {
status.active = hasType(status, "readout");
@ -152,7 +152,7 @@
getStatus: function(obj, status){
if (hasType(status, "input")){
var contextType = canvasContextType.get(obj);
status.active = contextType && contextType !== "2d";
status.active = contextType !== "2d";
}
else {
status.active = hasType(status, "readout");
@ -172,7 +172,7 @@
getStatus: function(obj, status){
if (hasType(status, "input")){
var contextType = canvasContextType.get(obj);
status.active = contextType && contextType !== "2d";
status.active = contextType !== "2d";
}
else {
status.active = hasType(status, "readout");