1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-05 11:32:20 +01: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,11 +21,13 @@
} }
} }
exports.setRandomSupplyByType = setRandomSupplyByType; 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){ apiNames.forEach(function(name){
var changedFunction = changedFunctions[name]; var changedFunction = changedFunctions[name];
var original = window.wrappedJSObject[changedFunction.object].prototype[name]; var original = window.wrappedJSObject[changedFunction.object].prototype[name];
if (changedFunction.getStatus(undefined, siteStatus).active){
Object.defineProperty( Object.defineProperty(
window.wrappedJSObject[changedFunction.object].prototype, window.wrappedJSObject[changedFunction.object].prototype,
name, name,
@ -37,8 +39,10 @@
return undef; return undef;
} }
var error = new Error(); var error = new Error();
var status = check({url: window.location.href, errorStack: error.stack}); if (checkStack(error.stack)){
var funcStatus = changedFunction.getStatus(this, status); return original;
}
var funcStatus = changedFunction.getStatus(this, siteStatus);
if (funcStatus.active){ if (funcStatus.active){
if (funcStatus.mode === "ask"){ if (funcStatus.mode === "ask"){
@ -71,6 +75,7 @@
} }
} }
); );
}
}); });
}; };
}()); }());

View File

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