aboutsummaryrefslogtreecommitdiff
path: root/18/script.js
blob: 6e80630d4384e33c0a645fe3b0d9d6e06fa75912 (plain)
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
function wait(ms) {
    return new Promise((resolve) => {
        window.setTimeout(resolve, ms);
    })
}

function terminalType(prefix, text) {
    if (text == null) text = '';
    const line = document.createElement('div');
    line.className = 'line';
    prefix = prefix.replace(/ /g, ' ')
    line.innerHTML = prefix;

    document.querySelector('.terminal').appendChild(line);

    function type(text, line) {
        if (text === '') {
            return Promise.resolve();
        }
        line.textContent = line.textContent + text.charAt(0);
        return wait(100).then(() => type(text.substr(1), line));
    }

    return wait(500).then(() => type(text, line));
}

document.querySelector('.terminal').textContent = '';

Promise.resolve()
    .then(() => terminalType('noah@loomans ~ $ ', 'cd Code/calculate_age'))
    .then(() => terminalType('noah@loomans ~/Code/calculate_age $ ', 'gcc calculate_age.c -o calculate_age'))
    .then(() => terminalType('noah@loomans ~/Code/calculate_age $ ', './calculate_age'))
    .then(() => terminalType('calculating', '.........'))
    .then(() => terminalType('  1111111        888888888'))
    .then(() => terminalType(' 1::::::1      88:::::::::88'))
    .then(() => terminalType('1:::::::1    88:::::::::::::88'))
    .then(() => terminalType('111:::::1   8::::::88888::::::8'))
    .then(() => terminalType('   1::::1   8:::::8     8:::::8'))
    .then(() => terminalType('   1::::1   8:::::8     8:::::8'))
    .then(() => terminalType('   1::::1    8:::::88888:::::8'))
    .then(() => terminalType('   1::::l     8:::::::::::::8'))
    .then(() => terminalType('   1::::l    8:::::88888:::::8'))
    .then(() => terminalType('   1::::l   8:::::8     8:::::8'))
    .then(() => terminalType('   1::::l   8:::::8     8:::::8'))
    .then(() => terminalType('   1::::l   8:::::8     8:::::8'))
    .then(() => terminalType('111::::::1118::::::88888::::::8'))
    .then(() => terminalType('1::::::::::1 88:::::::::::::88'))
    .then(() => terminalType('1::::::::::1   88:::::::::88'))
    .then(() => terminalType('111111111111     888888888'))
    .then(() => wait(2000))
    .then(() => document.querySelector('.down-arrow').classList.add('show'));

function resize() {
    const size = Math.min(window.innerWidth, window.innerHeight);
    const factor = size / 1080;
    document.documentElement.style.setProperty('--factor', factor);
}

if (window.location.hash === '#escape') {
    document.querySelector('#escape-room').style.display = 'block';
    document.querySelector('#no-escape-room').style.display = 'none';
}

resize();
window.addEventListener('resize', resize);