website/ts/error.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-02-28 11:01:35 +01:00
import Timeout = NodeJS.Timeout;
2021-01-20 23:22:18 +01:00
let intervalTime = 150;
let dataIndex = 0;
let stringPosition = 0;
2021-02-28 11:01:35 +01:00
let printTask: Timeout;
2021-01-20 23:22:18 +01:00
2021-02-28 14:09:57 +01:00
let terminal:HTMLElement;
let historyContainer:HTMLElement;
let promptContainer:HTMLElement;
2021-01-20 23:22:18 +01:00
function writeOut() {
// @ts-ignore
let currentData: { [key: string]: string } = data[dataIndex];
2021-01-20 23:22:18 +01:00
let currentText: string = 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
2021-01-20 23:22:18 +01:00
if(dataIndex < data.length){
// @ts-ignore
2021-01-20 23:22:18 +01:00
setTimeout(startNewTask, data[dataIndex - 1].postDelay);
}
}
}
function startNewTask() {
2021-02-28 14:09:57 +01:00
terminal = <HTMLElement> document.getElementsByClassName("terminal")[0];
historyContainer = <HTMLElement> terminal.getElementsByClassName("history")[0];
promptContainer = <HTMLElement> terminal.getElementsByClassName("prompt")[0];
printTask = setInterval(writeOut, intervalTime);
}