From cd37d7987d2cd46ebf05e6399eaded172e2c4d97 Mon Sep 17 00:00:00 2001 From: hackademix Date: Fri, 1 Nov 2019 14:55:12 +0100 Subject: Work-around for Youtube video elements positioned off-display at replacement time. --- src/content/PlaceHolder.js | 3 +++ src/content/media.js | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/content/PlaceHolder.js b/src/content/PlaceHolder.js index 4c860ec..7043caf 100644 --- a/src/content/PlaceHolder.js +++ b/src/content/PlaceHolder.js @@ -55,6 +55,9 @@ var PlaceHolder = (() => { for (let p of props) { destStyle[p] = srcStyle[p]; } + if (src.offsetTop < 0 && src.offsetTop <= (-src.offsetHeight)) { + destStyle.top = "0"; // fixes video player off-display position on Youtube + } destStyle.display = srcStyle.display !== "block" ? "inline-block" : "block"; } diff --git a/src/content/media.js b/src/content/media.js index 4b8f852..8a9526b 100644 --- a/src/content/media.js +++ b/src/content/media.js @@ -35,13 +35,11 @@ if ("MediaSource" in window) ns.on("capabilities", event => { notifyPage(); if (mediaBlocker) { - (async () => { + let exposedMime = `${mime} (MSE)`; + setTimeout(() => { let me = Array.from(document.querySelectorAll("video,audio")) .find(e => e.srcObject === ms || urls && urls.has(e.src)); - if (!me) return; - let exposedMime = `${mime} (MSE)`; - try { let ph = PlaceHolder.create("media", request); ph.replace(me); @@ -49,7 +47,7 @@ if ("MediaSource" in window) ns.on("capabilities", event => { } catch (e) { error(e); } - })(); + }, 0); throw new Error(`${exposedMime} blocked by NoScript`); } -- cgit v1.2.3