Use rAF to make the loading less stuttery
This commit is contained in:
parent
b5c34a278f
commit
e842808def
2 changed files with 21 additions and 17 deletions
|
@ -18,15 +18,21 @@ function initWaiting(elem: HTMLElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPage(page: string, elem: HTMLElement) {
|
async function loadPage(page: string, elem: HTMLElement) {
|
||||||
|
// Fetch page content
|
||||||
console.log(page + ": fetching");
|
console.log(page + ": fetching");
|
||||||
let html = await getPageHTML(page);
|
let html = await getPageHTML(page);
|
||||||
|
|
||||||
// Convert relative links to absolute
|
// Convert relative links to absolute
|
||||||
html = html.replace(/"\/wiki/gi, '"//tgstation13.org/wiki');
|
html = html.replace(/"\/wiki/gi, '"//tgstation13.org/wiki');
|
||||||
elem.innerHTML = html;
|
|
||||||
console.log(page + ": processing");
|
// Set as HTML content and run HTML manipulations on it
|
||||||
userscript(elem, page);
|
requestAnimationFrame(() => {
|
||||||
console.log(page + ": userscript applied");
|
elem.innerHTML = html;
|
||||||
elem.classList.remove("waiting");
|
console.log(page + ": processing");
|
||||||
|
userscript(elem, page);
|
||||||
|
console.log(page + ": userscript applied");
|
||||||
|
elem.classList.remove("waiting");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
type TabElements = { tabListItem: HTMLElement; tabContentItem: HTMLElement };
|
type TabElements = { tabListItem: HTMLElement; tabContentItem: HTMLElement };
|
||||||
|
|
|
@ -503,16 +503,14 @@ export default function (root: HTMLElement, docname: string) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.requestAnimationFrame(() => {
|
switch (docname) {
|
||||||
switch (docname) {
|
case "Guide_to_chemistry":
|
||||||
case "Guide_to_chemistry":
|
betterChemistry();
|
||||||
betterChemistry();
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
betterGeneric();
|
||||||
betterGeneric();
|
break;
|
||||||
break;
|
}
|
||||||
}
|
// Everything is loaded, remove loading bar
|
||||||
// Everything is loaded, remove loading bar
|
statusMessage.innerHTML = "";
|
||||||
statusMessage.innerHTML = "";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue