Use rAF to make the loading less stuttery

This commit is contained in:
Hamcha 2020-06-17 11:59:00 +02:00
parent b5c34a278f
commit e842808def
Signed by: hamcha
GPG key ID: 41467804B19A3315
2 changed files with 21 additions and 17 deletions

View file

@ -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');
// Set as HTML content and run HTML manipulations on it
requestAnimationFrame(() => {
elem.innerHTML = html; elem.innerHTML = html;
console.log(page + ": processing"); console.log(page + ": processing");
userscript(elem, page); userscript(elem, page);
console.log(page + ": userscript applied"); console.log(page + ": userscript applied");
elem.classList.remove("waiting"); elem.classList.remove("waiting");
});
} }
type TabElements = { tabListItem: HTMLElement; tabContentItem: HTMLElement }; type TabElements = { tabListItem: HTMLElement; tabContentItem: HTMLElement };

View file

@ -503,7 +503,6 @@ export default function (root: HTMLElement, docname: string) {
); );
} }
window.requestAnimationFrame(() => {
switch (docname) { switch (docname) {
case "Guide_to_chemistry": case "Guide_to_chemistry":
betterChemistry(); betterChemistry();
@ -514,5 +513,4 @@ export default function (root: HTMLElement, docname: string) {
} }
// Everything is loaded, remove loading bar // Everything is loaded, remove loading bar
statusMessage.innerHTML = ""; statusMessage.innerHTML = "";
});
} }