From 85aa8ec24efdb7f24de659391da2cfb2a8a53faa Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 14 Oct 2023 18:26:22 +0200 Subject: [PATCH] Fix missing download button --- src/entries/contentScript/player/main.ts | 4 ++++ src/lib/utils.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/entries/contentScript/player/main.ts b/src/entries/contentScript/player/main.ts index 85198e7..c626e70 100644 --- a/src/entries/contentScript/player/main.ts +++ b/src/entries/contentScript/player/main.ts @@ -2,6 +2,7 @@ import { getElementMounted } from '~/entries/contentScript/player/utils'; import { MountComponent } from '~/entries/contentScript/render'; import DownloadButton from '~/entries/contentScript/player/elements/DownloadButton.svelte'; import { settings } from '~/entries/contentScript/player/settings'; +import { sleep } from '~/lib/utils'; export let id = ''; @@ -26,6 +27,9 @@ async function onMessage(message: MessageEvent) { } const player = document.getElementById('vilos') as HTMLDivElement; + // sleep a bit to give the player time to render the new controls container when accessing the + // player via client site routing + await sleep(100); const controlsContainer = await getElementMounted( (p) => p.querySelector('#vilosControlsContainer'), player, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d45d83f..2681f9c 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -17,3 +17,7 @@ export async function waitForCallback T | undefine return promise; } + +export async function sleep(ms: number): Promise { + return new Promise((r) => setTimeout(r, ms)); +}