Merge pull request #1769 from javsezlol1/master

Loader.js fix () changed blending method and added preload, fixed logo too
This commit is contained in:
Vladimir Mandic
2023-07-20 09:59:57 -04:00
committed by GitHub
3 changed files with 43 additions and 19 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 62 KiB

+43 -19
View File
@@ -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 = `
<div id="splash" class="splash" style="background: ${dark ? 'black' : 'white'}">
<div class="loading"><div class="loader"></div></div>
<div class="splash-img" alt="logo" style="background-image: url(file=html/logo-bg-${dark ? 'dark' : 'light'}.jpg), url(file=html/logo-bg-${num}.jpg); background-blend-mode: ${dark ? 'darken' : 'lighten'}"></div>
</div>`;
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 = `
<div id="splash" class="splash" style="background: ${dark ? 'black' : 'white'}">
<div class="loading"><div class="loader"></div></div>
<div class="splash-img" alt="logo" style="background-image: url(file=html/logo-bg-${dark ? 'dark' : 'light'}.jpg), url(file=html/logo-bg-${num}.jpg); background-blend-mode: ${dark ? 'darken' : 'lighten'}"></div>
</div>`;
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;