diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-11-04 13:19:32 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-11-04 13:19:32 +0800 |
| commit | 77ae8b37e7d8b35835b26d7ff8c97614f2ffbb7e (patch) | |
| tree | 935d8afc2e0379b87a78c40fb85f2154629e62a4 /dest | |
| parent | 421a210bf0cad79e8a31855bb8a9ccb6844550c7 (diff) | |
fix for multi run
Diffstat (limited to 'dest')
| -rw-r--r-- | dest/js/hacktype.js | 13 |
1 files changed, 7 insertions, 6 deletions
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 () { |
