summaryrefslogtreecommitdiff
path: root/index.html
blob: 64c511ee1d73f3b0d9ab1b851ee4d5473c54e536 (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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
    <meta charset="UTF-8">
    <title>How Starscouts are you?</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet" integrity="sha384-XGjxtQfXaH2tnPFa9x+ruJTuLE3Aa6LhHSWRr1XeTyhezb4abCG4ccI5AkVDxqC+" crossorigin="anonymous">
</head>
<body>
    <div class="container" style="margin-top: 3rem; margin-bottom: 3rem;">
        <div class="card" style="max-width: 36rem; margin-left: auto; margin-right: auto;">
            <div class="card-body">
                <span class="text-muted" id="header">Welcome</span>
                <i class="bi-house-door" id="main-icon" style="font-size: 48px;display: block;margin-left: auto;margin-right: auto;width: max-content;"></i>
                <h3 style="text-align: center;" id="title">How Starscouts are you?</h3>

                <hr>
                <div id="home">
                    <p>Ever wondered how similar to Starscouts you are? (no, you have not)</p>
                    <p>Answer a few questions to get a result right away, so you can brag about how close to 100% you are.</p>
                    <p>This is just a fun project with no consequences whatsoever, so have fun!</p>

                    <div style="text-align: center;">
                        <span class="btn btn-primary disabled" onclick="privacy();" id="start-btn">Start!</span>
                    </div>

                    <noscript>
                        <style>
                            #start-btn {
                                display: none;
                            }
                        </style>
                        <div class="alert alert-danger" style="margin-bottom: 0;"><b>Error:</b> JavaScript is disabled on your browser. Enable JavaScript and refresh the page.</div>
                    </noscript>
                </div>
                <div id="privacy" style="display: none;">
                    <p>This website asks you to answer questions that can reach into personal territory.</p>
                    <p>To make sure this project stays fun, all the data you enter on this website is processed locally, on your own device,
                        and is never sent to any server, ever. The source code for this website is
                        <a target="_blank" href="https://github.com/equestria-dev/likeme">publicly available</a>, and if you are really paranoid, you can disconnect
                        from the internet from this point forward.</p>
                    <p>Do note, though, that your final results will be saved on your device's internal storage.
                        They will never be sent to a server (at least not without your consent) and you can delete them at any time.</p>

                    <div style="text-align: center;">
                        <span class="btn btn-primary" onclick="start();">Continue</span>
                        <span class="btn btn-outline-primary" onclick="location.reload();">I don't agree</span>
                    </div>
                </div>
                <div id="questions" style="display: none;">
                    <p id="answers" style="display: grid; grid-template-columns: 1fr 1fr; grid-gap: 5px;"></p>
                    <span class="btn btn-outline-primary" style="width: 100%;" id="back-btn">Back</span>
                </div>
                <div id="results" style="display: none;">
                    <p>That's how similar to Starscouts you are. But don't fret! Any score is good. What matters is that you are
                        yourself, everyone is unique in their own ways and that's what matters.</p>
                    <p>Did you like this? Let Starscouts know!</p>
                    <div style="text-align: center;">
                        <span class="btn btn-outline-primary" onclick="if (confirm('Are you sure you want to delete ALL the local data associated with this website? This includes your previous scores that could potentially be shared for a leaderboard in a future version.')) { localStorage.clear(); location.reload(); }">Delete local data</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="text-muted" style="text-align: center;">© 2024 The Starscouts, Equestria.dev Developers, All rights reserved.<br>All data is processed on-device, period.<br><br>Update: June 19th, 2024<br>Expirity: July 3nd, 2024</div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>

    <!--suppress JSCheckFunctionSignatures -->
    <script>
        if (new Date().getTime() >= 1719964800000) {
            document.head.innerHTML = "";
            document.body.innerHTML = "Expired :(";
        } else {
            window.questionStack = [];

            window.onload = () => {
                (async () => {
                    window.questions = (await (await fetch("./questions.txt")).text()).trim().split("\n").map(i => {
                        i = i.split("|");
                        return {
                            depends: !i[0].startsWith("-") ? parseInt(i[0]) - 1 : null,
                            name: i[1],
                            answers: i.slice(2)
                        }
                    });

                    window.answers = [];

                    document.getElementById("start-btn").classList.remove("disabled");
                })();
            }

            function privacy() {
                document.getElementById("home").style.display = "none";
                document.getElementById("privacy").style.display = "";
                document.getElementById("main-icon").className = "bi-shield";
                document.getElementById("title").innerText = "A word about privacy";
            }

            function start() {
                displayQuestion(0);
            }

            function shuffle(array) {
                let currentIndex = array.length, temporaryValue, randomIndex;

                while (0 !== currentIndex) {
                    randomIndex = Math.floor(Math.random() * currentIndex);
                    currentIndex -= 1;

                    temporaryValue = array[currentIndex];
                    array[currentIndex] = array[randomIndex];
                    array[randomIndex] = temporaryValue;
                }

                return array;
            }

            function countCorrect() {
                window.answers.push(true);
            }

            function countIncorrect() {
                window.answers.push(false);
            }

            function displayQuestion(i) {
                if (i >= questions.length) {
                    displayResults();
                    return;
                }

                if (questions[i].depends !== null && !answers[questions[i].depends]) {
                    while (questions[i].depends !== null && !answers[questions[i].depends]) {
                        countIncorrect();
                        i++;

                        if (i >= questions.length) {
                            displayResults();
                            return;
                        }
                    }

                    displayQuestion(i);
                    return;
                }

                let question = questions[i];
                questionStack.push(i);
                document.getElementById("questions").style.display = "";
                document.getElementById("privacy").style.display = "none";
                document.getElementById("main-icon").className = "bi-ui-radios";
                document.getElementById("title").innerText = question.name;
                document.getElementById("header").innerText = "Question " + (i + 1) + "/" + questions.length;
                document.getElementById("answers").innerHTML = shuffle(question.answers.map((j, k) => `
            <span class="btn btn-primary" onclick="count${k === 0 ? "Correct" : "Incorrect"}(); displayQuestion(${i + 1});">${j}</span>
            `)).join("");
                document.getElementById("back-btn").onclick = () => {
                    if (questionStack.length < 2) return;
                    answers.pop();
                    questionStack.pop();
                    let i = questionStack[questionStack.length - 1];
                    questionStack.pop();
                    displayQuestion(i);
                }
            }

            function displayResults() {
                let score = (answers.filter(i => i === true).length / answers.length) * 100;
                let data = JSON.parse(localStorage.getItem("scores") ?? "[]");
                data.push(score);
                localStorage.setItem("scores", JSON.stringify(data));

                document.getElementById("questions").style.display = "none";
                document.getElementById("results").style.display = "";
                document.getElementById("main-icon").className = "bi-award";
                document.getElementById("title").innerText = score.toFixed(2) + "%";
                document.getElementById("header").innerText = "Results";
            }
        }
    </script>
</body>
</html>