-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
109 lines (87 loc) · 3.08 KB
/
script.js
File metadata and controls
109 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
document.addEventListener("DOMContentLoaded", function () {
const terminalOutput = document.getElementById("terminal-output");
const terminalStatus = document.getElementById("terminal-status");
let isPaused = false;
let currentSentence = 0;
const sentences = [
"Why were we born?\nTo destroy the world, or to change it?\nThat's the question that haunts me every night.\nYes… every night.",
"So many people live behind their masks in this world.\nSweet smiles that quietly cause someone else to suffer.\nMaybe it's better to be fake, after all.",
"Turns out I'm no better than a loser.\nI'm used to running away from reality.\nMusic in my ears is enough to silence the world,\neven if it's only for a moment.",
"I want to go home.\nHow much longer do I have to endure?\nDoes enduring always mean carrying the pain?",
];
function updateStatus(status) {
terminalStatus.textContent = status + "...";
}
function typeText(text, callback) {
if (isPaused) return;
const outputElement = document.createElement("div");
outputElement.className = "output";
terminalOutput.appendChild(outputElement);
let currentLine = "";
let lineIndex = 0;
let charIndex = 0;
const lines = text.split("\n");
updateStatus("writing");
function typeChar() {
if (isPaused) return;
if (lineIndex < lines.length) {
if (charIndex < lines[lineIndex].length) {
currentLine += lines[lineIndex].charAt(charIndex);
outputElement.innerHTML =
currentLine + '<span class="typing-cursor"></span>';
charIndex++;
const delay = Math.random() * 50 + 30;
setTimeout(typeChar, delay);
} else {
outputElement.innerHTML = currentLine;
currentLine = "";
charIndex = 0;
lineIndex++;
if (lineIndex < lines.length) {
setTimeout(typeChar, 400);
} else {
updateStatus("thinking");
setTimeout(callback, 1500);
}
}
}
terminalOutput.scrollTop = terminalOutput.scrollHeight;
}
typeChar();
}
function clearTerminal() {
terminalOutput.innerHTML = "";
}
function displayNextSentence() {
if (isPaused || currentSentence >= sentences.length) return;
typeText(sentences[currentSentence], function () {
setTimeout(function () {
clearTerminal();
currentSentence++;
if (currentSentence < sentences.length) {
setTimeout(displayNextSentence, 800);
} else {
updateStatus("idle");
typeText("End of transmission.", function () {
updateStatus("completed");
});
}
}, 2000);
});
}
document.addEventListener("keydown", function (e) {
if (e.key === "Escape") {
isPaused = !isPaused;
if (isPaused) {
updateStatus("paused");
} else {
updateStatus("thinking");
if (currentSentence < sentences.length) {
displayNextSentence();
}
}
}
});
updateStatus("thinking");
setTimeout(displayNextSentence, 1000);
});