src/js/main.js
/** 
 * Preloads images in the filtered character data and converts to base64 representation.
*/
Preloads images in the filtered character data and converts to base64 representation.
Preloads images in the filtered character data and converts to base64 representation .
function preloadImages() {
  const totalLength = characterDataToSort.length;
  let imagesLoaded = 0;
  const loadImage = async (src) => {
    const blob = await fetch(src).then(res => res.blob());
    return new Promise((res, rej) => {
      const reader = new FileReader();
      reader.onload = ev => {
        progressBar(`Loading Image ${++imagesLoaded}`, Math.floor(imagesLoaded * 100 / totalLength));
        res(ev.target.result);
      };
      reader.onerror = rej;
      reader.readAsDataURL(blob);
    });
  };
  return Promise.all(characterDataToSort.map(async (char, idx) => {
    characterDataToSort[idx].img = await loadImage(imageRoot + char.img);
  }));
}
function preloadImages ( ) { const totalLength = characterDataToSort . length ; let imagesLoaded = 0 ; const loadImage = async ( src ) => { const blob = await fetch ( src ) . then ( res => res . blob ( ) ) ; return new Promise ( ( res , rej ) => { const reader = new FileReader ( ) ; reader . onload = ev => { progressBar ( ` ${ ++ imagesLoaded } ` , Math . floor ( imagesLoaded * 100 / totalLength ) ) ; res ( ev . target . result ) ; } ; reader . onerror = rej ; reader . readAsDataURL ( blob ) ; } ) ; } ; return Promise . all ( characterDataToSort . map ( async ( char , idx ) => { characterDataToSort [ idx ] . img = await loadImage ( imageRoot + char . img ) ; } ) ) ; }
Preloads images in the filtered character data and converts to base64 representation.
Preloads images in the filtered character data and converts to base64 representation .