const Maths = Math; // Yes, I'm that patriotic. const hellos = ['Hewwo!', 'Hello!', 'Awoo!']; const imaTypingSpeed = 100; const imaDeletingSpeed = 50; const imaGapTime = 1500; const imaTexts = ['dumbass', 'network engineer', 'Arch Linux user', 'programmer', 'furry', 'massive nerd']; function pickRandom(array) { return array[Maths.floor(Maths.random() * array.length)]; } window.addEventListener('load', (e) => { // ----- Hellos section ----- const helloEl = document.getElementById('helloText'); helloEl.innerText = pickRandom(hellos); // ----- I'm a text section ----- const imaEl = document.getElementById('imaText'); let imaSelection = 0; let imaCharIdx = 0; let currentIntervalID = -1; const typeFunc = () => { imaEl.innerText += imaTexts[imaSelection][imaCharIdx]; imaCharIdx++; if (imaCharIdx >= imaTexts[imaSelection].length) { clearInterval(currentIntervalID); setTimeout(() => { currentIntervalID = setInterval(deleteFunc, imaDeletingSpeed) }, imaGapTime); } }; const deleteFunc = () => { imaEl.innerText = imaEl.innerText.slice(0, -1); if (imaEl.innerText == '') { imaCharIdx = 0; imaSelection += 1; if (imaSelection >= imaTexts.length) { imaSelection = 0; } clearInterval(currentIntervalID); currentIntervalID = setInterval(typeFunc, imaTypingSpeed); } }; currentIntervalID = setInterval(typeFunc, imaTypingSpeed); });