forked from will0101/www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation-3.html
52 lines (48 loc) · 1.84 KB
/
animation-3.html
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
<script>
const commands4 = [
{ input: '$ tea https://github.com/teaxyz/demos/blob/main/hello-universe.sh<br><br>', output: `*** Interpreters ***<br><br>`},
{ input: '', output: `TypeScript: Hello, World!<br>`},
{ input: '', output: `Go: Hello, World!<br>`},
{ input: '', output: `JavaScript: Hello, World!<br>`},
{ input: '', output: `Perl: Hello, World!<br>`},
{ input: '', output: `Python: Hello, World!<br>`},
{ input: '', output: `Ruby: Hello World!<br>`},
{ input: '', output: `Lua: Hello, World!<br><br>`},
{ input: '', output: `*** Compilers ***<br><br>`},
{ input: '', output: `C: Hello, World!<br>`},
{ input: '', output: `Rust: Hello, World!<br>`},
];
let commandIndex4 = 0;
let command4 = commands4[commandIndex4];
let commandOutput4 = '';
function typeCommand4() {
if (commandIndex4 === commands4.length) {
return;
}
if (command4.input.length === 0) {
commandOutput4 += '\n' + command4.output + '\n';
document.querySelector('#terminal-output-4').innerHTML = commandOutput4;
commandIndex4++;
command4 = commands4[commandIndex4];
setTimeout(typeCommand4, 1000);
return;
}
let char = command4.input[0];
if (char === '$') {
char = '<span class="purple">$</span>';
}
commandOutput4 += char;
command4.input = command4.input.slice(1);
document.querySelector('#terminal-output-4').innerHTML = commandOutput4;
const delay = Math.floor(Math.random() * 100) + 50; // random delay between 50 and 150 ms
setTimeout(typeCommand4, delay);
}
const terminalOutput4 = document.querySelector('#terminal-output-4');
const observer4 = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
typeCommand4();
observer4.disconnect();
}
});
observer4.observe(terminalOutput4);
</script>