Player respects theme color

This commit is contained in:
WardPearce
2024-03-15 23:25:41 +13:00
parent 53a19f7af5
commit 900ed38752
2 changed files with 19 additions and 0 deletions
+7
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import Plyr, { type PlyrEvent } from 'plyr';
// Needed to overwrite Beercss styles.
import 'plyr/dist/plyr.css';
import { SponsorBlock, type Category } from 'sponsorblock-api';
import { onDestroy, onMount } from 'svelte';
@@ -13,6 +14,7 @@
sponsorBlockCategories
} from '../store';
import type { VideoPlay } from './Api/model';
import { getDynamicTheme } from './theme';
export let data: { video: VideoPlay };
@@ -78,6 +80,11 @@
return { src: format.url, size: Number(format.size.split('x')[1]), type: format.type };
})
};
document.documentElement.style.setProperty(
'--plyr-color-main',
(await getDynamicTheme())['--primary']
);
});
onDestroy(async () => {
+12
View File
@@ -0,0 +1,12 @@
export async function getDynamicTheme(mode?: string): Promise<Record<string, string>> {
const givenSettings = await window.ui("theme") as IBeerCssTheme;
// @ts-ignore
const themes: string = givenSettings[mode ? mode : (ui("mode") as string)];
let themeVars: Record<string, string> = {};
themes.split(";").forEach(keyVar => {
let [key, value] = keyVar.split(":");
themeVars[key] = value;
});
return themeVars;
}