From 05647ccb2ffe825da941746902a0a6fad508a36e Mon Sep 17 00:00:00 2001 From: Evan Khee Date: Sat, 4 May 2024 21:06:57 +0800 Subject: [PATCH] preload images --- script.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/script.js b/script.js index 93cbaca..dbd1b94 100644 --- a/script.js +++ b/script.js @@ -295,3 +295,22 @@ async function shareImage(imageUrl) { } // TODO implements a fallback to download the file } + +function preloadImages() { + let imageUrls = []; + // Collect all the image URLs from the storyline and questions arrays + for (let i = 0; i < storyline.length; i++) { + imageUrls.push(`images/${storyline[i][1]}`); + } + for (let i = 0; i < questions.length; i++) { + imageUrls.push(`images/${questions[i][1]}`); + } + // Preload the images + for (let i = 0; i < imageUrls.length; i++) { + let img = new Image(); + img.src = imageUrls[i]; + } +} + +// Call the preloadImages function to preload the images +preloadImages(); \ No newline at end of file