summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/hacktype.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/js/hacktype.js b/src/js/hacktype.js
index eb5595c0..4ff0463a 100644
--- a/src/js/hacktype.js
+++ b/src/js/hacktype.js
@@ -6,45 +6,45 @@ let interval = null;
function hackType() {
const elements = document.querySelectorAll(".hacktype");
-let intervals = [];
+const intervals = [];
elements.forEach((element) => {
let iteration = 0;
- intervals.push(
- setInterval(() => {
- element.innerText = element.innerText
+ const interval = setInterval(() => {
+ element.innerText = element.innerText
.split("")
.map((letter, index) => {
- if (index < iteration) {
+ if (index < iteration) {
return element.dataset.value[index];
- }
+ }
- return letters[Math.floor(Math.random() * 26)];
+ return letters[Math.floor(Math.random() * 26)];
})
.join("");
- if (iteration >= element.dataset.value.length) {
- clearInterval(intervals.shift());
- }
+ if (iteration >= element.dataset.value.length) {
+ clearInterval(interval);
+ }
+
+ iteration += 1 / 5;
+ }, 20);
- iteration += 1 / 5;
- }, 20)
- );
+ intervals.push(interval);
});
}
hackType(); // Call hackType initially
setInterval(() => {
-const intervals = document.querySelectorAll(".hacktype-interval");
-intervals.forEach((interval) => clearInterval(interval)); // Clear existing intervals
+const elements = document.querySelectorAll(".hacktype");
+elements.forEach((element) => 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", () => {
if (!document.hidden) {
hackType(); // Call hackType when the user comes back from being away
}
-});
+}); \ No newline at end of file