Merge pull request #3555 from thelounge/xpaw/apply-theme
Apply user theme as soon as possible on page load
This commit is contained in:
commit
3224c988b8
@ -61,6 +61,29 @@
|
|||||||
document.getElementById("loading").remove();
|
document.getElementById("loading").remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Apply user theme as soon as possible, before any other code loads
|
||||||
|
// This prevents flash of white while other code loads and socket connects
|
||||||
|
try {
|
||||||
|
const userSettings = JSON.parse(localStorage.getItem("settings"));
|
||||||
|
const themeEl = document.getElementById("theme");
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof userSettings.theme === "string" &&
|
||||||
|
themeEl.dataset.serverTheme !== userSettings.theme
|
||||||
|
) {
|
||||||
|
themeEl.attributes.href.value = `themes/${userSettings.theme}.css`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof userSettings.userStyles === "string" &&
|
||||||
|
!/[?&]nocss/.test(window.location.search)
|
||||||
|
) {
|
||||||
|
document.getElementById("user-specified-css").innerHTML = userSettings.userStyles;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger early service worker registration
|
// Trigger early service worker registration
|
||||||
if ("serviceWorker" in navigator) {
|
if ("serviceWorker" in navigator) {
|
||||||
navigator.serviceWorker.register("service-worker.js");
|
navigator.serviceWorker.register("service-worker.js");
|
||||||
|
Loading…
Reference in New Issue
Block a user