mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-31 09:01:56 +01:00
Protect reopened documents.
This commit is contained in:
parent
b6e5384945
commit
c8c311a82f
@ -114,34 +114,61 @@
|
||||
});
|
||||
});
|
||||
|
||||
// MutationObserver to intercept iframes while generating the DOM.
|
||||
var observer = new MutationObserver(allCallback);
|
||||
observer.observe(window.document.documentElement, {subtree: true, childList: true});
|
||||
window.document.addEventListener("DOMContentLoaded", function(){
|
||||
observer.disconnect();
|
||||
});
|
||||
// MutationObserver to intercept iFrames while generating the DOM.
|
||||
const observe = function(){
|
||||
var observer = new MutationObserver(allCallback);
|
||||
var observing = false;
|
||||
function observe(){
|
||||
if (!observing){
|
||||
observer.observe(window.document.documentElement, {subtree: true, childList: true});
|
||||
observing = true;
|
||||
}
|
||||
}
|
||||
observe();
|
||||
window.document.addEventListener("DOMContentLoaded", function(){
|
||||
if (observing){
|
||||
observer.disconnect();
|
||||
observing = false;
|
||||
}
|
||||
});
|
||||
return observe;
|
||||
}();
|
||||
|
||||
// MutationObserver does not trigger fast enough when document.write is used
|
||||
const documentWriteDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow.HTMLDocument.prototype, "write");
|
||||
const documentWriteDescriptor = Object.getOwnPropertyDescriptor(
|
||||
wrappedWindow.HTMLDocument.prototype,
|
||||
"write"
|
||||
);
|
||||
const documentWrite = documentWriteDescriptor.value;
|
||||
documentWriteDescriptor.value = exportFunction(function write(str){
|
||||
const parts = str.split(/(?=>)/);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}, window);
|
||||
Object.defineProperty(wrappedWindow.HTMLDocument.prototype, "write", documentWriteDescriptor);
|
||||
|
||||
const documentWritelnDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow.HTMLDocument.prototype, "writeln");
|
||||
const documentWritelnDescriptor = Object.getOwnPropertyDescriptor(
|
||||
wrappedWindow.HTMLDocument.prototype,
|
||||
"writeln"
|
||||
);
|
||||
const documentWriteln = documentWritelnDescriptor.value;
|
||||
documentWritelnDescriptor.value = exportFunction(function writeln(str){
|
||||
const parts = str.split(/(?=>)/);
|
||||
const parts = str.split(/(?=<)/);
|
||||
const length = parts.length - 1;
|
||||
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, parts[length]);
|
||||
}, window);
|
||||
|
Loading…
x
Reference in New Issue
Block a user