mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
fix(music-together): fix profile issue
This commit is contained in:
@ -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 */);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user