fix: fix an issue with videodatachangefired timing

This commit is contained in:
JellyBrick
2023-11-30 00:45:15 +09:00
parent 4c0cce89ee
commit d78da237fc
5 changed files with 59 additions and 26 deletions

View File

@ -4,6 +4,8 @@ import style from './style.css?inline';
import { createPlugin } from '@/utils';
import type { VideoDataChanged } from '@/types/video-data-changed';
export default createPlugin({
name: 'Album Color Theme',
restartNeeded: true,
@ -110,8 +112,8 @@ export default createPlugin({
onPlayerApiReady(playerApi) {
const fastAverageColor = new FastAverageColor();
playerApi.addEventListener('videodatachange', (name: string) => {
if (name === 'dataloaded') {
document.addEventListener('videodatachange', (event: CustomEvent<VideoDataChanged>) => {
if (event.detail.name === 'dataloaded') {
const playerResponse = playerApi.getPlayerResponse();
const thumbnail = playerResponse?.videoDetails?.thumbnail?.thumbnails?.at(0);
if (thumbnail) {