mirror of
https://codeberg.org/HPCesia/AstralHalo.git
synced 2025-04-08 17:34:27 +08:00
feat: add dynamic import utils
This commit is contained in:
parent
6deace3551
commit
5af071b0e7
@ -77,3 +77,24 @@ export function convertTimeToRelative(): void {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function loadScript(url: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = url;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject(new Error(`Failed to load script: ${url}`));
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
}
|
||||
|
||||
export function loadStylesheet(url: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = url;
|
||||
link.onload = () => resolve();
|
||||
link.onerror = () => reject(new Error(`Failed to load stylesheet: ${url}`));
|
||||
document.head.appendChild(link);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user