Skip to content

Commit fef4466

Browse files
committed
Loading messages won't repeat as often and cycle more slowly
1 parent 3affce8 commit fef4466

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/web/html/index.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// Load theme before the preloader is shown
3636
document.querySelector(":root").className = JSON.parse(localStorage.getItem("options")).theme;
3737

38-
// Cycle loading messages
38+
// Define loading messages
3939
const loadingMsgs = [
4040
"Proving P = NP...",
4141
"Computing 6 x 9...",
@@ -49,15 +49,28 @@
4949
"Navigating neural network...",
5050
"Importing machine learning..."
5151
];
52+
53+
// Shuffle array using Durstenfeld algorithm
54+
for (let i = loadingMsgs.length - 1; i > 0; --i) {
55+
const j = Math.floor(Math.random() * (i + 1));
56+
const temp = loadingMsgs[i];
57+
loadingMsgs[i] = loadingMsgs[j];
58+
loadingMsgs[j] = temp;
59+
}
60+
61+
// Show next loading message then move it to the end of the array
5262
function changeLoadingMsg() {
63+
const msg = loadingMsgs.shift();
5364
try {
5465
const el = document.getElementById("preloader-msg");
5566
el.className = "loading"; // Causes CSS transition on first message
56-
el.innerHTML = loadingMsgs[Math.floor(Math.random()*loadingMsgs.length)];
57-
} catch (err) {}
67+
el.innerHTML = msg;
68+
} catch (err) {} // Ignore errors if DOM not yet ready
69+
loadingMsgs.push(msg);
5870
}
71+
5972
changeLoadingMsg();
60-
window.loadingMsgsInt = setInterval(changeLoadingMsg, (Math.random()*500) + 500);
73+
window.loadingMsgsInt = setInterval(changeLoadingMsg, (Math.random() * 1000) + 1000);
6174
</script>
6275
</head>
6376
<body>

0 commit comments

Comments
 (0)