This commit is contained in:
2024-06-07 16:15:42 +08:00
parent ea7f4f538a
commit 614a983aa8
15 changed files with 834 additions and 464 deletions

View File

@ -109,6 +109,20 @@ function applyLanguage(dom, result) {
}
}
export function domLoad() {
if (document.readyState === 'loading') {
return new Promise((resolve, reject) => {
let tid = setTimeout(() => reject('timeout'), 30000);
document.addEventListener('DOMContentLoaded', () => {
clearTimeout(tid);
tid = void 0;
resolve();
});
});
}
return Promise.resolve();
}
export async function init(dom = document.body, options = {}) {
const lgid = getCurrentLgId();
let lgres = localStorage.getItem(getStorageKey(lgid));
@ -126,20 +140,7 @@ export async function init(dom = document.body, options = {}) {
}
try {
if (document.readyState === 'loading') {
return await new Promise((resolve, reject) => {
let tid = setTimeout(() => reject('timeout'), 30000);
document.addEventListener('DOMContentLoaded', () => {
clearTimeout(tid);
tid = void 0;
if (typeof options.callback === 'function') {
options.callback(result);
}
applyLanguage(dom, result);
resolve(result);
});
});
}
await domLoad();
if (typeof options.callback === 'function') {
options.callback(result);
}