File size: 13,100 Bytes
6614608
b0ddfe1
6614608
 
0d7cbff
 
 
 
 
6614608
 
0d7cbff
 
 
 
 
 
 
6614608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d7cbff
6614608
 
0d7cbff
6614608
0d7cbff
6614608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d7cbff
6614608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d7cbff
6614608
 
 
 
 
693972b
6614608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

<html>
<head>
    <title>A test of courage</title>
    <link href="https://fonts.googleapis.com/css2?family=Metal+Mania&display=swap" rel="stylesheet">
    <div id="stop-instruction" class="unselectable" style="position: absolute; top: 8%; left: 50%; transform: translate(-50%, -50%); color: #ffa502; font-size: 24px; font-family: 'Metal Mania', cursive; text-shadow: 0 0 10px #d35400, 0 0 20px #d35400; visibility: hidden; text-align: center;">
    Press 'Ctrl+R' to banish the spirit's jiggle!
</div>

    <style>

        .metal-mania-regular {
        font-family: "Metal Mania", system-ui;
        font-weight: 400;
        font-style: normal;
        }


        .arrow {
            position: absolute;
            top: 30%;
            left: 30%;
            width: 12px;
            visibility: hidden;
            pointer-events: none;
            z-index: 1000;
        }

        .pointer {
            position: absolute;
            top: 30%;
            left: 30%;
            width: 16px;
            visibility: hidden;
            pointer-events: none;
        }

        body {
            overflow-y: hidden;
            overflow-x: hidden;
            margin:0;
            padding:0;
            background: #262626;
            cursor: none;
        }
        .button {
            background: #171515;
            width: 100%;
            height: 100%;
            border-radius: 6px;
            border-width: 0px;
            font-size: 24px;
            transform: translateY(0);
            color: #ffa502;
            box-shadow: 0 0 50px #d35400;
            cursor: none;
            transition: .5s;
        }
        .darkened {
            background: #171515;
            opacity: 0.2;
            box-shadow: 0 0 0px 0px !important;
        }

       .hoverableMainButton:hover {
            text-shadow: 0 0 5px #d35400;
            box-shadow: 0 0 50px 20px #d35400;
        } 

        button:focus{
            outline: none;
        }

        .how {
            background: #171515;
            width: 100%;
            height: 100%;
            border-radius: 6px;
            border-width: 0px;
            font-size: 18px;
            transform: translateY(0);
            color: #ffa502;
            box-shadow: 0 0 20px #d35400;
            cursor: none;
        }

        #ouija {
            box-shadow: 0 0 20px #d35400;
        }

        .unselectable {
            user-select: none;
            -moz-user-select: none;
            -khtml-user-select: none;
            -webkit-user-select: none;
            -o-user-select: none;
        }

        @media only screen and (max-width: 760px) {
            .button {
                display: none;
            }
            .mobile-warning {
                display: block;
            }
        }

    </style>

    <script>
        var recordingStatus = "off" // off, recording, replaying
        var freshRecording = []
        var prevTime = undefined
        var prevX = undefined
        var prevY = undefined
        var offsetX = 0
        var offsetY = 0
        var userMoveCount = 0

        var hideAllCursors = function() {
            const pointer = document.getElementById("pointer")
            const arrow = document.getElementById("arrow")
            pointer.style.visibility = "hidden";
            arrow.style.visibility = "hidden";
        }
        var paintCursorWithOffset = function(cursor, realX, realY) {
            const w = window.innerWidth;
            const h = window.innerHeight;
            var x = realX + offsetX
            var y = realY + offsetY
            if (x > w-24) {
                x = Math.max(realX, w-24)
            }
            if (y > h-24) {
                y = Math.max(realY, h-24)
            }
            if (x < 0) {
                x = 0
            }
            if (y < 0) {
                y = 0
            }
            cursor.style.top = y + "px"; 
            cursor.style.left = x + "px"; 
        }
        var mouseMovedOnBackground = function(event) {
            const x = event.clientX
            const y = event.clientY
            if (recordingStatus === "recording") {
                const time = Date.now()
                const timeDiff = time - prevTime
                const xDiff = x - prevX
                const yDiff = y - prevY
                prevTime = time
                freshRecording.push([timeDiff, xDiff, yDiff])
            }
            prevX = x
            prevY = y
            const pointer = document.getElementById("pointer")
            pointer.style.visibility = "hidden";
            const arrow = document.getElementById("arrow")
            arrow.style.visibility = "visible";
            paintCursorWithOffset(arrow, prevX, prevY)
            userMoveCount += 1
        }
        var mouseMovedOnButton = function(event) {
            if (recordingStatus === "replaying") {
                mouseMovedOnBackground(event);
                return;
            }
            const x = event.clientX
            const y = event.clientY
            prevX = x
            prevY = y
            const arrow = document.getElementById("arrow")
            arrow.style.visibility = "hidden";
            const pointer = document.getElementById("pointer")
            pointer.style.visibility = "visible";
            paintCursorWithOffset(pointer, x, y)
            userMoveCount += 1
        }
        var getCandidateVal = function(x, y, candidateX, candidateY) {
            return Math.sqrt((x - candidateX) * (x-candidateX) + (y - candidateY) * (y - candidateY))
        }
        var choose = function(previousBestCandidate, candidateX, candidateY, x, y) {
            const candidateVal = getCandidateVal(x, y, candidateX, candidateY)
            if (!previousBestCandidate || candidateVal < previousBestCandidate.val) {
                return {
                    'val': candidateVal,
                    'x': candidateX,
                    'y': candidateY
                }
            }
            return previousBestCandidate
        }
        var mouseMovedOnHowdy = function(event) {
            if (recordingStatus === "replaying") {
                mouseMovedOnBackground(event);
                return;
            }
            const x = event.clientX
            const y = event.clientY

            // Offset mouse to the nearest side of howdy-button.
            const bounds = document.getElementById("how").getBoundingClientRect()
            var bestCandidate = null
            bestCandidate = choose(bestCandidate, bounds.left-10, y, x, y) // left
            bestCandidate = choose(bestCandidate, x, bounds.top-10, x, y) // up
            bestCandidate = choose(bestCandidate, x, bounds.bottom+10, x, y) // down
            bestCandidate = choose(bestCandidate, bounds.right+10, y, x, y) // right
            offsetX = bestCandidate.x - x
            offsetY = bestCandidate.y - y

            prevX = x
            prevY = y
            const pointer = document.getElementById("pointer")
            pointer.style.visibility = "hidden";
            const arrow = document.getElementById("arrow")
            arrow.style.visibility = "visible";
            paintCursorWithOffset(arrow, x, y)
            userMoveCount += 1
        }
        var recordingIndex = 0
        var step = 0
        var recursiveTimerReplay = function() {
            const rec = recordings[recordingIndex]
            if (step >= rec.length) {
                // Instead of stopping, just reset the step and move to the next recording
                step = 0
                recordingIndex = (recordingIndex + 1) % recordings.length
                // Do not return, just let the recursive timer continue
            }

            const currTime = Date.now()
            if (currTime - prevTime >= rec[step][0]) {
                offsetX = offsetX + rec[step][1]
                offsetY = offsetY + rec[step][2]
                step = step + 1
                paintCursorWithOffset(document.getElementById("arrow"), prevX, prevY)
                prevTime = currTime
            }
            setTimeout(() => { recursiveTimerReplay() }, 0)
        }
        var replayMovements = function(event) {
            const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
            if (width < 800 || typeof(prevX) == "undefined" || userMoveCount < 5) {
                alert("Sorry, we can't do the trick on your device. Please try again with a desktop/laptop that has a mouse attached and has screen width of at least 800 pixels.")
                return
            }
            recordingStatus = "replaying"
            arrow = document.getElementById("arrow")
            paintCursorWithOffset(arrow, prevX, prevY)
            document.getElementById("pointer").style.visibility = "hidden";
            arrow.style.visibility = "visible";
            document.getElementById("butt").classList.add("darkened")
            document.getElementById("butt").classList.remove("hoverableMainButton")
            document.getElementById("howdiv").style.visibility = "hidden";
            document.getElementById("ouija").style.visibility = "hidden";
            document.getElementById("stop-instruction").style.visibility = "visible";
            prevTime = Date.now()
            recursiveTimerReplay()
        }
        var recordMovements = function(event) {
            const REC_TIME = 15000
            freshRecording = []
            recordingStatus = "recording"
            prevTime = Date.now()
            document.getElementById('recordButton').style.display = 'none'; 
            document.getElementById('buttdiv').style.display = 'none';
            for (var j=REC_TIME; j>0; j-=1000) {
                const bah = REC_TIME - j
                setTimeout(() => console.log(bah / 1000), bah)
            }
            setTimeout(() => {
                document.getElementById('buttdiv').style.display = 'block'; 
                recordingStatus = false;
                recordings.push(freshRecording)
                console.log('finished recording');
                console.log(freshRecording)
            }, REC_TIME)
        }

        document.addEventListener('contextmenu', e => {
            if (recordingStatus == 'replaying') {
                e.preventDefault();
            }
        });

    </script>
</head>
<body>

    <div id="bg" style="position: absolute; width: 100%; height: 100%"></div>

    <button id="recordButton" style="position: absolute; top: 45%; left: 37%; z-index: 999; display: none;">
        Record
    </button>

    <noscript><h1>This website requires JavaScript in order to do a trick. Please enable JavaScript and refresh.</h1></noscript>

    <h1 class="mobile-warning" style="display: none;">
        This website requires a laptop/desktop device with a mouse, and a sufficiently large screen. Try with another device?
    </h1>

    <div id="buttdiv" class="unselectable" style="position: absolute; width: 400px; height: 100px; top: 50%; left: 50%; margin: -50px 0 0 -200px;">
        <button id="butt" class="button hoverableMainButton unselectable" tabindex="-1">
            I'm not afraid to click<br>buttons on the internet
        </button>
    </div>

    <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" title="Explanation video (all the answers you need are here)" style="display: none;"></a>
    <div id="howdiv" class="unselectable" style="position: absolute; width: 200px; height: 50px; right: 50px; bottom: 50px; margin: -50px 0 0 -200px; visibility: visible;">
        <button id="how" class="how unselectable" tabindex="-1">
            How this works
        </button>
    </div>

    <div id="ouija" class="unselectable" style="position: absolute; left: 50px; bottom: 50px; visibility: visible;">
        <a href="https://ouija.attejuvonen.fi" target="_blank">
            <img src="ouija.jpg" style="width: 100px; cursor: none;">
        </a>
    </div>
    <script>

        document.body.addEventListener('mouseleave', e => { hideAllCursors() })
        document.getElementById('bg').addEventListener('mousemove', e => { mouseMovedOnBackground(e) })
        document.getElementById('butt').addEventListener('mousemove', e => { mouseMovedOnButton(e) })
        document.getElementById('butt').addEventListener('click', e => { replayMovements(e) })
        document.getElementById('recordButton').addEventListener('click', e => { recordMovements(e) })
        document.getElementById('how').addEventListener('mousemove', e => { mouseMovedOnHowdy(e) })
        document.getElementById('how').addEventListener('mouseleave', e => { offsetX = 0; offsetY = 0; })
        document.getElementById('ouija').addEventListener('mousemove', e => { mouseMovedOnButton(e) })

    </script>
    <script src="recordings.js"></script>

    <img id="arrow" class="arrow" src="arrow_m.png" />
    <img id="pointer" class="pointer" src="pointer.png" />

    <script async defer data-domain="attejuvonen.fi" src="https://plausible.io/js/plausible.js"></script>
    
</body>
</html>