mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 18:42:00 +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:
parent
b2823cbd8d
commit
82bb25d0f2
@ -21,56 +21,61 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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];
|
||||||
|
|
||||||
Object.defineProperty(
|
if (changedFunction.getStatus(undefined, siteStatus).active){
|
||||||
window.wrappedJSObject[changedFunction.object].prototype,
|
Object.defineProperty(
|
||||||
name,
|
window.wrappedJSObject[changedFunction.object].prototype,
|
||||||
{
|
name,
|
||||||
enumerable: true,
|
{
|
||||||
configureable: false,
|
enumerable: true,
|
||||||
get: function(){
|
configureable: false,
|
||||||
if (!window.location.href){
|
get: function(){
|
||||||
return undef;
|
if (!window.location.href){
|
||||||
}
|
return undef;
|
||||||
var error = new Error();
|
}
|
||||||
var status = check({url: window.location.href, errorStack: error.stack});
|
var error = new Error();
|
||||||
var funcStatus = changedFunction.getStatus(this, status);
|
if (checkStack(error.stack)){
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
var funcStatus = changedFunction.getStatus(this, siteStatus);
|
||||||
|
|
||||||
if (funcStatus.active){
|
if (funcStatus.active){
|
||||||
if (funcStatus.mode === "ask"){
|
if (funcStatus.mode === "ask"){
|
||||||
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch (funcStatus.mode){
|
else {
|
||||||
case "allow":
|
return original;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}());
|
}());
|
@ -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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user