This commit is contained in:
choelzl 2022-02-23 20:57:23 +01:00
parent cb0a79d1e0
commit 617adace59
Signed by: sora
GPG Key ID: A362EA0491E2EEA0

View File

@ -89,7 +89,7 @@ $(async function () {
preloaded = false; preloaded = false;
var loadedimages = {}; var loadedimages = {};
for (let i=0; i<emotes.length; i++) { for (let i=0; i<emotes.length; i++) {
var image = new Image(); const image = new Image();
image.onload = function () { image.onload = function () {
loadcount++; loadcount++;
if (loadcount == loadtotal) preloaded = true; if (loadcount == loadtotal) preloaded = true;
@ -102,19 +102,16 @@ $(async function () {
const loadImagesTwitch = async(emotesId) => { const loadImagesTwitch = async(emotesId) => {
let loadcount = 0; const promiseArray = [];
let loadtotal = emotesId.length;
var localPreloaded = false;
for (let i=0; i<emotesId.length; i++) { for (let i=0; i<emotesId.length; i++) {
var image = new Image(); promiseArray.push(new Promise(resolve => {
image.onload = function () { const image = new Image();
loadcount++; image.onload = () => resolve();
if (loadcount == loadtotal) localPreloaded = true;
};
image.src = "https://static-cdn.jtvnw.net/emoticons/v2/" + emotesId[i] + "/default/dark/2.0"; image.src = "https://static-cdn.jtvnw.net/emoticons/v2/" + emotesId[i] + "/default/dark/2.0";
img_map[emotesId[i]] = image; img_map[emotesId[i]] = image;
}));
} }
await waitFor(_ => localPreloaded === true); await Promise.all(promiseArray);
return true; return true;
} }