From fef446687aa3426767a2d73abefdd75af48f7e31 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 9 Jun 2017 15:21:39 +0000 Subject: [PATCH] Loading messages won't repeat as often and cycle more slowly --- src/web/html/index.html | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/web/html/index.html b/src/web/html/index.html index 4c596be9..6bf88185 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -35,7 +35,7 @@ // Load theme before the preloader is shown document.querySelector(":root").className = JSON.parse(localStorage.getItem("options")).theme; - // Cycle loading messages + // Define loading messages const loadingMsgs = [ "Proving P = NP...", "Computing 6 x 9...", @@ -49,15 +49,28 @@ "Navigating neural network...", "Importing machine learning..." ]; + + // Shuffle array using Durstenfeld algorithm + for (let i = loadingMsgs.length - 1; i > 0; --i) { + const j = Math.floor(Math.random() * (i + 1)); + const temp = loadingMsgs[i]; + loadingMsgs[i] = loadingMsgs[j]; + loadingMsgs[j] = temp; + } + + // Show next loading message then move it to the end of the array function changeLoadingMsg() { + const msg = loadingMsgs.shift(); try { const el = document.getElementById("preloader-msg"); el.className = "loading"; // Causes CSS transition on first message - el.innerHTML = loadingMsgs[Math.floor(Math.random()*loadingMsgs.length)]; - } catch (err) {} + el.innerHTML = msg; + } catch (err) {} // Ignore errors if DOM not yet ready + loadingMsgs.push(msg); } + changeLoadingMsg(); - window.loadingMsgsInt = setInterval(changeLoadingMsg, (Math.random()*500) + 500); + window.loadingMsgsInt = setInterval(changeLoadingMsg, (Math.random() * 1000) + 1000);