mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
parent
f3d1ca80f5
commit
506f062c07
@ -21,6 +21,13 @@
|
||||
|
||||
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
|
||||
|
||||
function changeProperty(object, name, type, changed){
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
||||
const original = descriptor[type];
|
||||
descriptor[type] = changed;
|
||||
Object.defineProperty(object, name, descriptor);
|
||||
registerChangedProperty(object, name, descriptor, type, original);
|
||||
}
|
||||
const changedProperties = [];
|
||||
// eslint-disable-next-line max-params
|
||||
function registerChangedProperty(object, name, descriptor, type, original){
|
||||
@ -61,13 +68,10 @@
|
||||
return window;
|
||||
}
|
||||
};
|
||||
contentWindowDescriptor.get = exportFunction(
|
||||
changeProperty(wrappedConstructor.prototype, "contentWindow", "get", exportFunction(
|
||||
Object.getOwnPropertyDescriptor(contentWindowTemp, "contentWindow").get,
|
||||
window
|
||||
);
|
||||
Object.defineProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor);
|
||||
registerChangedProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor,
|
||||
"get", originalContentWindowGetter);
|
||||
));
|
||||
|
||||
const contentDocumentDescriptor = Object.getOwnPropertyDescriptor(
|
||||
constructor.prototype,
|
||||
@ -83,13 +87,10 @@
|
||||
return document;
|
||||
}
|
||||
};
|
||||
contentDocumentDescriptor.get = exportFunction(
|
||||
changeProperty(wrappedConstructor.prototype, "contentDocument", "get", exportFunction(
|
||||
Object.getOwnPropertyDescriptor(contentDocumentTemp, "contentDocument").get,
|
||||
window
|
||||
);
|
||||
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
|
||||
@ -123,19 +124,15 @@
|
||||
protectionDefinition.methods.forEach(function(method){
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, method);
|
||||
const original = descriptor.value;
|
||||
descriptor.value = exportFunction(eval(`(function ${method}(){
|
||||
changeProperty(object, method, "value", exportFunction(eval(`(function ${method}(){
|
||||
const value = arguments.length?
|
||||
original.apply(this, window.Array.from(arguments)):
|
||||
original.call(this);
|
||||
allCallback();
|
||||
return value;
|
||||
})`), window);
|
||||
Object.defineProperty(object, method, descriptor);
|
||||
registerChangedProperty(object, method, descriptor, "value", original);
|
||||
})`), window));
|
||||
});
|
||||
protectionDefinition.getters.forEach(function(property){
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
||||
const getter = descriptor.get;
|
||||
const temp = eval(`({
|
||||
get ${property}(){
|
||||
const ret = this.${property};
|
||||
@ -143,9 +140,10 @@
|
||||
return ret;
|
||||
}
|
||||
})`);
|
||||
descriptor.get = exportFunction(Object.getOwnPropertyDescriptor(temp, property).get, window);
|
||||
Object.defineProperty(object, property, descriptor);
|
||||
registerChangedProperty(object, property, descriptor, "get", getter);
|
||||
changeProperty(object, property, "get", exportFunction(
|
||||
Object.getOwnPropertyDescriptor(temp, property).get,
|
||||
window
|
||||
));
|
||||
});
|
||||
protectionDefinition.setters.forEach(function(property){
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
||||
@ -158,9 +156,9 @@
|
||||
return ret;
|
||||
}
|
||||
})`);
|
||||
descriptor.set = exportFunction(Object.getOwnPropertyDescriptor(temp, property).set, window);
|
||||
Object.defineProperty(object, property, descriptor);
|
||||
registerChangedProperty(object, property, descriptor, "set", setter);
|
||||
changeProperty(object, property, "set", exportFunction(
|
||||
Object.getOwnPropertyDescriptor(temp, property).set, window
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
@ -188,63 +186,72 @@
|
||||
}();
|
||||
|
||||
// MutationObserver does not trigger fast enough when document.write is used
|
||||
const documentWriteDescriptor = Object.getOwnPropertyDescriptor(
|
||||
const documentWriteDescriptorOnHTMLDocument = Object.getOwnPropertyDescriptor(
|
||||
wrappedWindow.HTMLDocument.prototype,
|
||||
"write"
|
||||
) || Object.getOwnPropertyDescriptor(
|
||||
);
|
||||
const documentWriteDescriptor = documentWriteDescriptorOnHTMLDocument || Object.getOwnPropertyDescriptor(
|
||||
wrappedWindow.Document.prototype,
|
||||
"write"
|
||||
);
|
||||
const documentWrite = documentWriteDescriptor.value;
|
||||
documentWriteDescriptor.value = exportFunction(function write(markup){
|
||||
for (let i = 0, l = arguments.length; i < l; i += 1){
|
||||
const str = "" + arguments[i];
|
||||
// weird problem with waterfox and google docs
|
||||
const parts = (
|
||||
str.match(/^\s*<!doctype/i) &&
|
||||
!str.match(/frame/i)
|
||||
)? [str]: str.split(/(?=<)/);
|
||||
const length = parts.length;
|
||||
const scripts = window.document.getElementsByTagName("script");
|
||||
for (let i = 0; i < length; i += 1){
|
||||
documentWrite.call(this, parts[i]);
|
||||
allCallback();
|
||||
if (scripts.length && scripts[scripts.length - 1].src){
|
||||
observe();
|
||||
changeProperty(
|
||||
documentWriteDescriptorOnHTMLDocument?
|
||||
wrappedWindow.HTMLDocument.prototype:
|
||||
wrappedWindow.Document.prototype,
|
||||
"write", "value", exportFunction(function write(markup){
|
||||
for (let i = 0, l = arguments.length; i < l; i += 1){
|
||||
const str = "" + arguments[i];
|
||||
// weird problem with waterfox and google docs
|
||||
const parts = (
|
||||
str.match(/^\s*<!doctype/i) &&
|
||||
!str.match(/frame/i)
|
||||
)? [str]: str.split(/(?=<)/);
|
||||
const length = parts.length;
|
||||
const scripts = window.document.getElementsByTagName("script");
|
||||
for (let i = 0; i < length; i += 1){
|
||||
documentWrite.call(this, parts[i]);
|
||||
allCallback();
|
||||
if (scripts.length && scripts[scripts.length - 1].src){
|
||||
observe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, window);
|
||||
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor);
|
||||
registerChangedProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor,
|
||||
"value", documentWrite);
|
||||
}, window)
|
||||
);
|
||||
|
||||
const documentWritelnDescriptor = Object.getOwnPropertyDescriptor(
|
||||
const documentWritelnDescriptorOnHTMLDocument = Object.getOwnPropertyDescriptor(
|
||||
wrappedWindow.HTMLDocument.prototype,
|
||||
"writeln"
|
||||
) || Object.getOwnPropertyDescriptor(
|
||||
);
|
||||
const documentWritelnDescriptor = documentWritelnDescriptorOnHTMLDocument || Object.getOwnPropertyDescriptor(
|
||||
wrappedWindow.Document.prototype,
|
||||
"writeln"
|
||||
);
|
||||
const documentWriteln = documentWritelnDescriptor.value;
|
||||
documentWritelnDescriptor.value = exportFunction(function writeln(markup){
|
||||
for (let i = 0, l = arguments.length; i < l; i += 1){
|
||||
const str = "" + arguments[i];
|
||||
const parts = str.split(/(?=<)/);
|
||||
const length = parts.length;
|
||||
const scripts = window.document.getElementsByTagName("script");
|
||||
for (let i = 0; i < length; i += 1){
|
||||
documentWrite.call(this, parts[i]);
|
||||
allCallback();
|
||||
if (scripts.length && scripts[scripts.length - 1].src){
|
||||
observe();
|
||||
changeProperty(
|
||||
documentWritelnDescriptorOnHTMLDocument?
|
||||
wrappedWindow.HTMLDocument.prototype:
|
||||
wrappedWindow.Document.prototype,
|
||||
"writeln", "value", exportFunction(
|
||||
function writeln(markup){
|
||||
for (let i = 0, l = arguments.length; i < l; i += 1){
|
||||
const str = "" + arguments[i];
|
||||
const parts = str.split(/(?=<)/);
|
||||
const length = parts.length;
|
||||
const scripts = window.document.getElementsByTagName("script");
|
||||
for (let i = 0; i < length; i += 1){
|
||||
documentWrite.call(this, parts[i]);
|
||||
allCallback();
|
||||
if (scripts.length && scripts[scripts.length - 1].src){
|
||||
observe();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
documentWriteln.call(this, "");
|
||||
}, window);
|
||||
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor);
|
||||
registerChangedProperty(wrappedWindow.HTMLDocument.prototype, "writeln", documentWritelnDescriptor,
|
||||
"value", documentWriteln);
|
||||
documentWriteln.call(this, "");
|
||||
},
|
||||
window
|
||||
)
|
||||
);
|
||||
};
|
||||
}());
|
@ -61,6 +61,14 @@
|
||||
{
|
||||
"version": "0.5.14Alpha20190821",
|
||||
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.14Alpha20190821-an+fx.xpi"
|
||||
},
|
||||
{
|
||||
"version": "0.5.14Alpha20190911",
|
||||
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.14Alpha20190911-an+fx.xpi"
|
||||
},
|
||||
{
|
||||
"version": "0.5.14Alpha20190912",
|
||||
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-0.5.14Alpha20190912-an+fx.xpi"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user