diff --git a/lib/intercept.js b/lib/intercept.js index b96618f..a2427ff 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -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; } } - } - ); + ); + } }); }; }()); \ No newline at end of file diff --git a/lib/modifiedAPI.js b/lib/modifiedAPI.js index ef5a314..27e974e 100644 --- a/lib/modifiedAPI.js +++ b/lib/modifiedAPI.js @@ -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");