From 77ae8b37e7d8b35835b26d7ff8c97614f2ffbb7e Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 4 Nov 2023 13:19:32 +0800 Subject: fix for multi run --- dest/js/hacktype.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'dest') diff --git a/dest/js/hacktype.js b/dest/js/hacktype.js index 4c53e83d..c05f8907 100644 --- a/dest/js/hacktype.js +++ b/dest/js/hacktype.js @@ -9,7 +9,7 @@ function hackType() { var intervals = []; elements.forEach(function (element) { var iteration = 0; - intervals.push(setInterval(function () { + var interval = setInterval(function () { element.innerText = element.innerText.split("").map(function (letter, index) { if (index < iteration) { return element.dataset.value[index]; @@ -17,21 +17,22 @@ function hackType() { return letters[Math.floor(Math.random() * 26)]; }).join(""); if (iteration >= element.dataset.value.length) { - clearInterval(intervals.shift()); + clearInterval(interval); } iteration += 1 / 5; - }, 20)); + }, 20); + intervals.push(interval); }); } hackType(); // Call hackType initially setInterval(function () { - var intervals = document.querySelectorAll(".hacktype-interval"); - intervals.forEach(function (interval) { + var elements = document.querySelectorAll(".hacktype"); + elements.forEach(function (element) { return clearInterval(interval); }); // Clear existing intervals hackType(); // Call hackType again -}, 10000); // Repeat every 5 seconds +}, 10000); // Repeat every 10 seconds // Check if the document becomes visible again document.addEventListener("visibilitychange", function () { -- cgit v1.2.3