Play nice with the Viewhance extension.

This commit is contained in:
hackademix 2022-02-20 18:11:15 +01:00
parent a9653fc7c9
commit 3f92a4a5e9
1 changed files with 12 additions and 8 deletions

View File

@ -21,24 +21,23 @@
if (ns.embeddingDocument) {
let suspended;
let suspender = new MutationObserver(records => {
if (suspended) return;
suspended = document.body && document.body.firstElementChild;
if (suspended) {
debug("Suspending ", suspended.src, suspended);
debug("Suspending ", suspended);
suspended.autoplay = false;
suspended.src = "data:";
suspender.disconnect();
if (suspended.pause) suspended.pause();
suspended.src = suspended.currentSrc = "data:";
if (ns.policy) replace();
}
});
suspender.observe(document, {childList: true, subtree: true});
let replace = () => {
if (suspended) {
suspended.src = document.URL;
suspended.autoplay = true;
} else {
suspender.disconnect();
debug("Restoring suspended", suspended);
suspended.src = suspended.currentSrc = document.URL;
}
for (let policyType of ["object", "media"]) {
let request = {
id: `noscript-${policyType}-doc`,
@ -49,6 +48,11 @@ if (ns.embeddingDocument) {
};
if (ns.allows(policyType)) {
suspender.disconnect();
if (suspended) {
suspended.autoplay = true;
if (suspended.play) suspended.play();
}
let handler = PlaceHolder.handlerFor(policyType);
if (handler && handler.selectFor(request).length > 0) {
seen.record({policyType, request, allowed: true});