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');
|
||||||
|
|
||||||
|
// 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 };
|
||||||
|
|
|
@ -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 = "";
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue