Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Video button: one place over YouTube's thumbnail previews (#560) (#591)

Ahmed Nefzaoui3d11d7ba7c5d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1978b0c5..ff55f0e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
- Dark mode no longer draws a bright white line under the menu bar, across the whole window, in the Classic and Native themes ([#379](https://github.com/anefzaoui/misterdownloadmanager/issues/379)).
- Windows: a download's progress window with a title of 256 characters or more (a torrent with a long name, or a file name kept whole in a folder too deep to shorten it) has MDM's own title bar again, instead of the system's drawn above it (part of [#540](https://github.com/anefzaoui/misterdownloadmanager/issues/540)).
- Windows: closing the window hides MDM in the notification area again when Windows keeps its icon among the hidden icons (behind ^), where a new icon goes. MDM took the icon for missing there and left the window in the taskbar instead; it now does that only when Windows has no icon of MDM's at all ([#545](https://github.com/anefzaoui/misterdownloadmanager/issues/545), [#534](https://github.com/anefzaoui/misterdownloadmanager/issues/534), [#527](https://github.com/anefzaoui/misterdownloadmanager/issues/527)).
+- The browser's **video button** over YouTube's thumbnail previews keeps one place, so it can be clicked: it moved to another corner when the preview showed its sound and captions buttons, back when they hid as the pointer reached it, and away again, and it followed the preview as it shrank. Over the same video it now only moves on to a free corner, never back, and it stays put while the pointer is on it ([#560](https://github.com/anefzaoui/misterdownloadmanager/issues/560)).
- Chrome, Edge, Brave and the other Chromium browsers: a download the extension leaves to the browser keeps the name and folder another extension gives it (Save In's folders, or any extension's own download into a folder). The extension's answer for it counted as a name of its own, an empty one, and when the extension was the newest installed it won: the file landed in the Downloads folder, and the browser could warn of a conflict between the two extensions ([#578](https://github.com/anefzaoui/misterdownloadmanager/issues/578)).
### Added
diff --git a/ROADMAP.md b/ROADMAP.md
index d8aa7d55..2beef46a 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -535,6 +535,9 @@ These ship in a later version, when they're ready.
### Bugs being looked into
+- πŸ”„ The video button jumping between corners over YouTube's thumbnail previews, out of the
+ pointer's reach ([#560](https://github.com/anefzaoui/misterdownloadmanager/issues/560)): fix in
+ review
- πŸ”„ A submenu staying open, its item lit beside the one under the pointer, while the pointer
moved on through the menu ([#579](https://github.com/anefzaoui/misterdownloadmanager/issues/579)): fix in review
- πŸ”„ Chromium browsers: another extension's file names and folders (Save In's) lost while MDM's
diff --git a/extension/video.js b/extension/video.js
index 3d914464..cb012214 100644
--- a/extension/video.js
+++ b/extension/video.js
@@ -145,6 +145,8 @@
let chosen = false; // the user put it where it is (dragged it, on this site): theirs, never moved for a page's control
let auto = { v: null, at: null, t: 0 }; // the spot found for this video, kept for a moment
const AUTO_MS = 400;
+ // Where it is on the screen, while the pointer is on it (#560): { v, left, top }.
+ let pinned = null;
let video = null; // the video it is over
// A video gone from under its button (#503): a hover-to-play preview (YouTube's thumbnails)
// stops as soon as the pointer leaves it for the button, since the page sees the pointer go.
@@ -368,12 +370,20 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }
// Where it goes now: the place the user gave it, else the default corner, or the next corner
// free of the page's own controls (a thumbnail's watch-later button at the top right, #421).
+ // Over the same video it only ever goes on to the next corner, never back to one it left: a
+ // hover-to-play preview (YouTube's thumbnails, #560) shows its sound and captions buttons while
+ // the pointer is over the video and hides them as the pointer reaches the button, so going back
+ // when they hide, then away again when they show, kept the button jumping from under the pointer.
+ const CORNERS = [{ x: 0, y: 0 }, { x: 0, y: 1 }, { x: 1, y: 1 }];
function spot(r, w, h, roomX, roomY) {
if (chosen) return place;
const now = Date.now();
- if (auto.v === video && now - auto.t < AUTO_MS) return auto.at;
- let at = place;
- for (const c of [place, { x: 0, y: 0 }, { x: 0, y: 1 }, { x: 1, y: 1 }]) {
+ const same = auto.v === video;
+ if (same && now - auto.t < AUTO_MS) return auto.at;
+ const order = [place, ...CORNERS];
+ const from = same ? Math.max(0, order.indexOf(auto.at)) : 0;
+ let at = same ? auto.at : place;
+ for (const c of order.slice(from)) {
const left = r.left + INSET + c.x * roomX;
const top = r.top + INSET + c.y * roomY;
if (!onControl({ left, top, right: left + w, bottom: top + h }, video, r)) {
@@ -388,6 +398,13 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }
function position() {
if (!video) return;
const { r, w, roomX, roomY } = rects();
+ // The pointer on it (or its menu open): it stays where it is, whatever the video does
+ // meanwhile. A preview that grows while the pointer is over it and shrinks back when the
+ // pointer goes (#560) would otherwise take the button from under the pointer.
+ if (!dragging && pinned && pinned.v === video && (menuOpen || root.matches(":hover"))) {
+ if (menuOpen) placeMenu(pinned.top, pinned.left, w);
+ return;
+ }
// A narrow video gets the icon only.
pill.classList.toggle("compact", r.width < 360);
// Held for a video gone (#503): where it was, not a corner found anew over what the page
@@ -400,6 +417,7 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }
const visBottom = Math.min(r.bottom, innerHeight) - INSET - h;
const top = Math.min(Math.max(r.top + INSET + at.y * roomY, visTop), Math.max(visTop, visBottom));
root.style.setProperty("transform", `translate(${Math.round(left)}px, ${Math.round(top)}px)`, "important");
+ pinned = { v: video, left, top };
if (menuOpen) placeMenu(top, left, w);
}
@@ -453,6 +471,7 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }
// `now`: at once and whatever has the focus (dismissed, the video gone).
function hide(now) {
if (!now && (menuOpen || dragging || keyboardOn())) return;
+ pinned = null;
if (now) {
held = null;
closeMenu();
@@ -717,6 +736,9 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }
}
place = snap(d.at);
chosen = true;
+ // It snaps to its corner although the pointer is still on it (#560's pin is for a video
+ // that changes under a still pointer, not for the user's own move).
+ pinned = null;
position();
lastMove = Date.now();
// Remembered per site, not in a private window (it would keep the site's name), and the
diff --git a/tools/extension/e2e.mjs b/tools/extension/e2e.mjs
index 24632e30..a064fde7 100644
--- a/tools/extension/e2e.mjs
+++ b/tools/extension/e2e.mjs
@@ -19,7 +19,8 @@
// forwarded), names (Content-Disposition), redirect, leadon (a page going to the file by script, #374), form (POST, 303), alt (Alt+click leaves it
// to the browser), opened (a PDF or MP3 the browser would show or play), spot (the video button
// clear of the page's controls, #421), preview (the video button kept over a hover-to-play
-// preview the page stopped as the pointer went to it, #503), csp (the video button
+// preview the page stopped as the pointer went to it, #503), steady (the video button keeping one place over
+// a preview that grows and shows its own buttons while hovered, #560), csp (the video button
// under a strict CSP), hls (the stream a player loaded), streams (HLS and DASH players handed over
// by the button, the right-click menu and the media list, and read by yt-dlp; #155; also with no
// .m3u8 or .mpd, served as text/plain or octet-stream, #171), sniffed (#171 without yt-dlp: such
@@ -1818,6 +1819,81 @@ const CASES = {
return done.join("; ");
},
+ // #560: YouTube's thumbnail previews grow while the pointer is over them and show their own
+ // sound button at the top right, and shrink back and hide it once the pointer leaves for the
+ // button. The button keeps one place as the pointer goes to it and rests on it, and a click
+ // sends the video.
+ async steady(t) {
+ await t.session.navigate(`${LAB}/page?video=${encodeURIComponent("/gen/1M/clip.mp4")}`);
+ await t.session.evaluate(`(() => {
+ const v = document.querySelector("#video");
+ v.style.transition = "transform 150ms linear";
+ let timer = 0;
+ v.addEventListener("mouseenter", () => {
+ v.style.transform = "scale(1.08)";
+ clearTimeout(timer);
+ timer = setTimeout(() => {
+ const r = v.getBoundingClientRect();
+ const c = document.createElement("button");
+ c.id = "preview-sound";
+ c.textContent = "sound";
+ c.style.cssText = "position:fixed;left:" + (r.right - 48) + "px;top:" + (r.top + 6) + "px;width:40px;height:40px;z-index:9";
+ document.body.appendChild(c);
+ }, 300);
+ });
+ v.addEventListener("mouseleave", () => {
+ clearTimeout(timer);
+ v.style.transform = "";
+ document.getElementById("preview-sound")?.remove();
+ document.body.dataset.left = String(Number(document.body.dataset.left || 0) + 1);
+ });
+ return true;
+ })()`);
+ const v0 = await rect(t.session, "#video");
+ const first = await hover(t.session, v0);
+ if (!first) throw new Error("no button over the preview");
+ // The preview grown, its sound button shown: the button takes a free corner.
+ await until("the preview's sound button", 3000, () => t.session.evaluate(`Boolean(document.getElementById("preview-sound"))`));
+ await sleep(900);
+ const c = await rect(t.session, "#preview-sound");
+ const b = await rect(t.session, "mdm-video-button");
+ if (!b) throw new Error("the button went as the preview started");
+ if (b.l < c.r && b.r > c.l && b.t < c.b && b.b > c.t) throw new Error(`the button covers the preview's sound button: ${JSON.stringify({ b, c })}`);
+ // The pointer goes to it in steps, then rests on it: the page shrinks the preview and hides
+ // its sound button. Where the button is, every step and every 100 ms while it rests.
+ const v = await rect(t.session, "#video");
+ const from = [(v.l + v.r) / 2, (v.t + v.b) / 2];
+ const to = [b.l + 14, (b.t + b.b) / 2];
+ const seen = [];
+ const at = async (what) => {
+ const r = await rect(t.session, "mdm-video-button");
+ seen.push(r ? `${what} ${Math.round(r.l)},${Math.round(r.t)}` : `${what} gone`);
+ return r;
+ };
+ for (let i = 1; i <= 8; i++) {
+ await t.session.mouse(from[0] + ((to[0] - from[0]) * i) / 8, from[1] + ((to[1] - from[1]) * i) / 8);
+ await sleep(60);
+ await at(`step ${i}`);
+ }
+ await until("the page saw the pointer leave the preview", 3000, () => t.session.evaluate(`Number(document.body.dataset.left || 0) > 0`));
+ const landed = await at("on it");
+ for (let i = 0; i < 25; i++) {
+ await sleep(100);
+ await at(`rest ${i}`);
+ }
+ // E2E_STEADY_SHOT: a screenshot after the pointer rested on it, for a PR's body.
+ if (process.env.E2E_STEADY_SHOT && t.session.screenshot) await t.session.screenshot(process.env.E2E_STEADY_SHOT);
+ const moved = seen.filter((x) => {
+ const m = /(-?\d+),(-?\d+)$/.exec(x);
+ return !m || !landed || Math.abs(m[1] - landed.l) > 2 || Math.abs(m[2] - landed.t) > 2;
+ });
+ if (!landed || moved.length) throw new Error(`the button moved: ${seen.join("; ")} (landed at ${landed ? `${Math.round(landed.l)},${Math.round(landed.t)}` : "none"})`);
+ const address = await clickButton(t.session, landed);
+ if (address !== `${LAB}/gen/1M/clip.mp4`) throw new Error(`the video window got ${address}`);
+ await t.session.mouse(5, 5);
+ return `${Math.abs(first.l - b.l) > 2 || Math.abs(first.t - b.t) > 2 ? "moved" : "stayed"} off the preview's sound button, at ${Math.round(b.l - v.l)},${Math.round(b.t - v.t)}; then still for ${seen.length} looks (8 steps there, 2.5 s on it while the preview shrank and hid its button), sent ${address.replace(LAB, "")}`;
+ },
+
// A player playing a stream (a blob: in the page): the button sends the manifest it loaded.
async hls(t) {
await t.session.navigate(`${LAB}/page?hls=1`);