fix(music-together): fix profile issue

This commit is contained in:
JellyBrick
2025-05-11 22:59:53 +09:00
parent 8f18fb80ea
commit efc8038210
2 changed files with 37 additions and 14 deletions

View File

@ -1,13 +1,30 @@
export const waitForElement = <T extends Element>(
selector: string,
options: {
maxRetry?: number;
retryInterval?: number;
} = {
maxRetry: -1,
retryInterval: 100,
},
): Promise<T> => {
return new Promise<T>((resolve) => {
let retryCount = 0;
const maxRetry = options.maxRetry ?? -1;
const retryInterval = options.retryInterval ?? 100;
const interval = setInterval(() => {
if (maxRetry > 0 && retryCount >= maxRetry) {
clearInterval(interval);
return;
}
const elem = document.querySelector<T>(selector);
if (!elem) return;
if (!elem) {
retryCount++;
return;
}
clearInterval(interval);
resolve(elem);
}, 100 /* ms */);
}, retryInterval /* ms */);
});
};