Skip to content

Commit

Permalink
Merge pull request AUTOMATIC1111#1769 from javsezlol1/master
Browse files Browse the repository at this point in the history
Loader.js fix () changed blending method and added preload, fixed logo too
  • Loading branch information
vladmandic committed Jul 20, 2023
2 parents a3ab302 + c3cbeb6 commit ff44556
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
Binary file modified html/logo-bg-dark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified html/logo-bg-light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 43 additions & 19 deletions javascript/loader.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ff44556

Please sign in to comment.