forked from AUTOMATIC1111/stable-diffusion-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AUTOMATIC1111#1769 from javsezlol1/master
Loader.js fix () changed blending method and added preload, fixed logo too
- Loading branch information
Showing
3 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |