website/js/error.js
2021-03-24 23:50:27 +01:00

42 lines
No EOL
1.2 KiB
JavaScript

let intervalTime = 150;
let dataIndex = 0;
let stringPosition = 0;
let printTask;
let terminal;
let historyContainer;
let promptContainer;
function writeOut() {
let currentData = data[dataIndex];
let currentText = currentData["strings"];
promptContainer.innerText = promptContainer.innerText + currentText.charAt(stringPosition);
stringPosition++;
if(stringPosition > currentText.length){
stringPosition = 0
dataIndex++;
historyContainer.innerHTML = historyContainer.innerHTML + "$&nbsp;" + promptContainer.innerHTML + "<br><span class=\"gray\">" + currentData["output"] + "</span><br><br>";
promptContainer.innerHTML = "";
clearInterval(printTask);
// @ts-ignore
if(dataIndex < data.length){
// @ts-ignore
setTimeout(startNewTask, data[dataIndex - 1].postDelay);
}
}
}
function startNewTask() {
terminal = document.getElementsByClassName("terminal")[0];
historyContainer = terminal.getElementsByClassName("history")[0];
promptContainer = terminal.getElementsByClassName("prompt")[0];
printTask = setInterval(writeOut, intervalTime);
}
if(document.querySelector(".terminal-window") != null){
startNewTask();
}