mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
parent
069165e8d6
commit
f3d1ca80f5
@ -12,8 +12,37 @@
|
|||||||
scope = require.register("./iframeProtection", {});
|
scope = require.register("./iframeProtection", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settings = require("./settings");
|
||||||
|
const lists = require("./lists");
|
||||||
|
|
||||||
|
function isWhitelisted(url){
|
||||||
|
return lists.get("white").match(url) || settings.get("blockMode", url).startsWith("allow");
|
||||||
|
}
|
||||||
|
|
||||||
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
|
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
|
||||||
|
|
||||||
|
const changedProperties = [];
|
||||||
|
// eslint-disable-next-line max-params
|
||||||
|
function registerChangedProperty(object, name, descriptor, type, original){
|
||||||
|
changedProperties.push({object, name, descriptor, type, original});
|
||||||
|
}
|
||||||
|
if (settings.isStillDefault){
|
||||||
|
settings.onloaded(function(){
|
||||||
|
if (isWhitelisted(window.location)){
|
||||||
|
changedProperties.forEach(function({object, name, descriptor, type, original}){
|
||||||
|
descriptor[type] = original;
|
||||||
|
Object.defineProperty(object, name, descriptor);
|
||||||
|
});
|
||||||
|
changedProperties.length = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (isWhitelisted(window.location)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
["HTMLIFrameElement", "HTMLFrameElement"].forEach(function(constructorName){
|
["HTMLIFrameElement", "HTMLFrameElement"].forEach(function(constructorName){
|
||||||
const constructor = window[constructorName];
|
const constructor = window[constructorName];
|
||||||
const wrappedConstructor = wrappedWindow[constructorName];
|
const wrappedConstructor = wrappedWindow[constructorName];
|
||||||
@ -37,6 +66,8 @@
|
|||||||
window
|
window
|
||||||
);
|
);
|
||||||
Object.defineProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor);
|
Object.defineProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor);
|
||||||
|
registerChangedProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor,
|
||||||
|
"get", originalContentWindowGetter);
|
||||||
|
|
||||||
const contentDocumentDescriptor = Object.getOwnPropertyDescriptor(
|
const contentDocumentDescriptor = Object.getOwnPropertyDescriptor(
|
||||||
constructor.prototype,
|
constructor.prototype,
|
||||||
@ -57,6 +88,8 @@
|
|||||||
window
|
window
|
||||||
);
|
);
|
||||||
Object.defineProperty(wrappedConstructor.prototype, "contentDocument", contentDocumentDescriptor);
|
Object.defineProperty(wrappedConstructor.prototype, "contentDocument", contentDocumentDescriptor);
|
||||||
|
registerChangedProperty(wrappedConstructor.prototype, "contentDocument", contentDocumentDescriptor,
|
||||||
|
"get", originalContentDocumentGetter);
|
||||||
});
|
});
|
||||||
[
|
[
|
||||||
// useless as length could be obtained before the iframe is created and window.frames === window
|
// useless as length could be obtained before the iframe is created and window.frames === window
|
||||||
@ -98,9 +131,11 @@
|
|||||||
return value;
|
return value;
|
||||||
})`), window);
|
})`), window);
|
||||||
Object.defineProperty(object, method, descriptor);
|
Object.defineProperty(object, method, descriptor);
|
||||||
|
registerChangedProperty(object, method, descriptor, "value", original);
|
||||||
});
|
});
|
||||||
protectionDefinition.getters.forEach(function(property){
|
protectionDefinition.getters.forEach(function(property){
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
||||||
|
const getter = descriptor.get;
|
||||||
const temp = eval(`({
|
const temp = eval(`({
|
||||||
get ${property}(){
|
get ${property}(){
|
||||||
const ret = this.${property};
|
const ret = this.${property};
|
||||||
@ -110,6 +145,7 @@
|
|||||||
})`);
|
})`);
|
||||||
descriptor.get = exportFunction(Object.getOwnPropertyDescriptor(temp, property).get, window);
|
descriptor.get = exportFunction(Object.getOwnPropertyDescriptor(temp, property).get, window);
|
||||||
Object.defineProperty(object, property, descriptor);
|
Object.defineProperty(object, property, descriptor);
|
||||||
|
registerChangedProperty(object, property, descriptor, "get", getter);
|
||||||
});
|
});
|
||||||
protectionDefinition.setters.forEach(function(property){
|
protectionDefinition.setters.forEach(function(property){
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
||||||
@ -124,6 +160,7 @@
|
|||||||
})`);
|
})`);
|
||||||
descriptor.set = exportFunction(Object.getOwnPropertyDescriptor(temp, property).set, window);
|
descriptor.set = exportFunction(Object.getOwnPropertyDescriptor(temp, property).set, window);
|
||||||
Object.defineProperty(object, property, descriptor);
|
Object.defineProperty(object, property, descriptor);
|
||||||
|
registerChangedProperty(object, property, descriptor, "set", setter);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -179,6 +216,8 @@
|
|||||||
}
|
}
|
||||||
}, window);
|
}, window);
|
||||||
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor);
|
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor);
|
||||||
|
registerChangedProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor,
|
||||||
|
"value", documentWrite);
|
||||||
|
|
||||||
const documentWritelnDescriptor = Object.getOwnPropertyDescriptor(
|
const documentWritelnDescriptor = Object.getOwnPropertyDescriptor(
|
||||||
wrappedWindow.HTMLDocument.prototype,
|
wrappedWindow.HTMLDocument.prototype,
|
||||||
@ -205,5 +244,7 @@
|
|||||||
documentWriteln.call(this, "");
|
documentWriteln.call(this, "");
|
||||||
}, window);
|
}, window);
|
||||||
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor);
|
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor);
|
||||||
|
registerChangedProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor,
|
||||||
|
"value", documentWriteln);
|
||||||
};
|
};
|
||||||
}());
|
}());
|
@ -3,7 +3,7 @@ Version 0.5.14:
|
|||||||
- reevaluated logging message levels
|
- reevaluated logging message levels
|
||||||
|
|
||||||
new features:
|
new features:
|
||||||
-
|
- remove iframe protection from whitelisted pages
|
||||||
|
|
||||||
fixes:
|
fixes:
|
||||||
- improved option pages on mobile
|
- improved option pages on mobile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user