mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-15 14:09:36 +02:00
parent
35c6a82480
commit
951277e922
10 changed files with 411 additions and 178 deletions
51
lib/intercept.js
Normal file
51
lib/intercept.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
const {changedFunctions} = require("./modifiedAPI");
|
||||
var apiNames = Object.keys(changedFunctions);
|
||||
var undef;
|
||||
|
||||
exports.intercept = function intercept({subject: window}, {check, ask, notify}){
|
||||
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});
|
||||
if (status.type.indexOf(changedFunction.type) !== -1){
|
||||
if (status.mode === "ask"){
|
||||
status.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
|
||||
}
|
||||
switch (status.mode){
|
||||
case "allow":
|
||||
return original;
|
||||
case "fake":
|
||||
notify({url: window.location.href, errorStack: error.stack}, window);
|
||||
return changedFunction.fake || undef;
|
||||
//case "block":
|
||||
default:
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue