diff --git a/html/logo-bg-dark.jpg b/html/logo-bg-dark.jpg index 7ca8c71dc..713b5e57e 100644 Binary files a/html/logo-bg-dark.jpg and b/html/logo-bg-dark.jpg differ diff --git a/html/logo-bg-light.jpg b/html/logo-bg-light.jpg index 401e5d794..3c7405dd4 100644 Binary files a/html/logo-bg-light.jpg and b/html/logo-bg-light.jpg differ diff --git a/javascript/loader.js b/javascript/loader.js index 1c838ce98..9563fd308 100644 --- a/javascript/loader.js +++ b/javascript/loader.js @@ -1,19 +1,43 @@ -async function createSplash() { - const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; - const num = Math.floor(Math.random() * 7) + 1; - const splash = ` -
-
-
-
`; - document.body.insertAdjacentHTML('beforeend', splash); - console.log('createSplash', { 'system-theme': dark ? 'dark' : 'light' }); -} - -async function removeSplash() { // called at the end of setHints - const splash = document.getElementById('splash'); - if (splash) splash.remove(); - console.log('removeSplash'); -} - -window.onload = createSplash; +async function preloadImages() { + const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; + const imagePromises = []; + const num = Math.floor(Math.random() * 7) + 1; + const imageUrls = [ + `file=html/logo-bg-${dark ? 'dark' : 'light'}.jpg`, + `file=html/logo-bg-${num}.jpg` + ]; + for (const url of imageUrls) { + const img = new Image(); + const promise = new Promise((resolve, reject) => { + img.onload = resolve; + img.onerror = reject; + }); + img.src = url; + imagePromises.push(promise); + } + try { + await Promise.all(imagePromises); + } catch (error) { + console.error('Error preloading images:', error); + } +} + +async function createSplash() { + await preloadImages(); + const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; + const num = Math.floor(Math.random() * 7) + 1; + const splash = ` +
+
+
+
`; + document.body.insertAdjacentHTML('beforeend', splash); + console.log('createSplash', dark); +} +async function removeSplash() { + const splash = document.getElementById('splash'); + if (splash) splash.remove(); + console.log('removeSplash'); +} + +window.onload = createSplash;