-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
index.js
1169 lines (1025 loc) · 32 KB
/
index.js
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* global Element */
/**
* The Annoying Site
* https://theannoyingsite.com
*
* Author:
* Feross Aboukhadijeh
* https://feross.org
*
* Patreon:
* If you enjoyed this, please support me on Patreon!
* https://www.patreon.com/feross
*/
const SCREEN_WIDTH = window.screen.availWidth
const SCREEN_HEIGHT = window.screen.availHeight
const WIN_WIDTH = 480
const WIN_HEIGHT = 360
const VELOCITY = 15
const MARGIN = 15
const TOP_MARGIN = 50
const TICK_LENGTH = 50
const HIDDEN_STYLE = 'position: fixed; width: 1px; height: 1px; overflow: hidden; top: -10px; left: -10px;'
const ART = [
`
┊┊ ☆┊┊┊┊☆┊┊☆ ┊┊┊┊┊
┈┈┈┈╭━━━━━━╮┊☆ ┊┊
┈☆ ┈┈┃╳╳╳▕╲▂▂╱▏┊┊
┈┈☆ ┈┃╳╳╳▕▏▍▕▍▏┊┊
┈┈╰━┫╳╳╳▕▏╰┻╯▏┊┊
☆ ┈┈┈┃╳╳╳╳╲▂▂╱┊┊┊
┊┊☆┊╰┳┳━━┳┳╯┊ ┊ ☆┊
`,
`
░░▓▓░░░░░░░░▓▓░░
░▓▒▒▓░░░░░░▓▒▒▓░
░▓▒▒▒▓░░░░▓▒▒▒▓░
░▓▒▒▒▒▓▓▓▓▒▒▒▒▓░
░▓▒▒▒▒▒▒▒▒▒▒▒▒▒▓
▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓
▓▒▒▒░▓▒▒▒▒▒░▓▒▒▓
▓▒▒▒▓▓▒▒▒▓▒▓▓▒▒▓
▓▒░░▒▒▒▒▒▒▒▒▒░░▓
▓▒░░▒▓▒▒▓▒▒▓▒░░▓
░▓▒▒▒▓▓▓▓▓▓▓▒▒▓░
░░▓▒▒▒▒▒▒▒▒▒▒▓░░
░░░▓▓▓▓▓▓▓▓▓▓░░░
`
]
const SEARCHES = [
'where should i bury the body',
'why does my eye twitch',
'why is my poop green',
'why do i feel so empty',
'why do i always feel hungry',
'why do i always have diarrhea',
'why does my anus itch',
'why does my belly button smell',
'why does my cat attack me',
'why does my dog eat poop',
'why does my fart smell so bad',
'why does my mom hate me',
'why does my pee smell bad',
'why does my poop float',
'proof that the earth is flat'
]
const VIDEOS = [
'albundy.mp4',
'badger.mp4',
'cat.mp4',
'hasan.mp4',
'heman.mp4',
'jozin.mp4',
'nyan.mp4',
'rickroll.mp4',
'space.mp4',
'trolol.mp4'
]
const FILE_DOWNLOADS = [
'cat-blue-eyes.jpg',
'cat-ceiling.jpg',
'cat-crosseyes.jpg',
'cat-cute.jpg',
'cat-hover.jpg',
'cat-marshmellows.jpg',
'cat-small-face.jpg',
'cat-smirk.jpg',
'patreon.png'
]
const PHRASES = [
'The wheels on the bus go round and round, round and round, round and round. The wheels on the bus go round and round, all through the town!',
'Dibidi ba didi dou dou, Di ba didi dou, Didi didldildidldidl houdihoudi dey dou',
'I like fuzzy kittycats, warm eyes, and pretending household appliances have feelings',
'I\'ve never seen the inside of my own mouth because it scares me to death.',
'hee haw hee haw hee haw hee haw hee haw hee haw hee haw hee haw hee haw hee haw hee haw',
'abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak',
'eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo eyo'
]
const LOGOUT_SITES = {
AOL: ['GET', 'https://my.screenname.aol.com/_cqr/logout/mcLogout.psp?sitedomain=startpage.aol.com&authLev=0&lang=en&locale=us'],
'AOL 2': ['GET', 'https://api.screenname.aol.com/auth/logout?state=snslogout&r=' + Math.random()],
Amazon: ['GET', 'https://www.amazon.com/gp/flex/sign-out.html?action=sign-out'],
Blogger: ['GET', 'https://www.blogger.com/logout.g'],
Delicious: ['GET', 'https://www.delicious.com/logout'], // works!
DeviantART: ['POST', 'https://www.deviantart.com/users/logout'],
DreamHost: ['GET', 'https://panel.dreamhost.com/index.cgi?Nscmd=Nlogout'],
Dropbox: ['GET', 'https://www.dropbox.com/logout'],
eBay: ['GET', 'https://signin.ebay.com/ws/eBayISAPI.dll?SignIn'],
Gandi: ['GET', 'https://www.gandi.net/login/out'],
GitHub: ['GET', 'https://github.com/logout'],
GMail: ['GET', 'https://mail.google.com/mail/?logout'],
Google: ['GET', 'https://www.google.com/accounts/Logout'], // works!
Hulu: ['GET', 'https://secure.hulu.com/logout'],
Instapaper: ['GET', 'https://www.instapaper.com/user/logout'],
Linode: ['GET', 'https://manager.linode.com/session/logout'],
LiveJournal: ['POST', 'https://www.livejournal.com/logout.bml', { 'action:killall': '1' }],
MySpace: ['GET', 'https://www.myspace.com/index.cfm?fuseaction=signout'],
NetFlix: ['GET', 'https://www.netflix.com/Logout'],
'New York Times': ['GET', 'https://www.nytimes.com/logout'],
Newegg: ['GET', 'https://secure.newegg.com/NewMyAccount/AccountLogout.aspx'],
Photobucket: ['GET', 'https://photobucket.com/logout'],
Skype: ['GET', 'https://secure.skype.com/account/logout'],
Slashdot: ['GET', 'https://slashdot.org/my/logout'],
SoundCloud: ['GET', 'https://soundcloud.com/logout'],
'Steam Community': ['GET', 'https://steamcommunity.com/?action=doLogout'],
'Steam Store': ['GET', 'https://store.steampowered.com/logout/'],
ThinkGeek: ['GET', 'https://www.thinkgeek.com/brain/account/login.cgi?a=lo'],
Threadless: ['GET', 'https://www.threadless.com/logout'],
Tumblr: ['GET', 'https://www.tumblr.com/logout'],
Vimeo: ['GET', 'https://vimeo.com/log_out'],
Wikipedia: ['GET', 'https://en.wikipedia.org/w/index.php?title=Special:UserLogout'],
'Windows Live': ['GET', 'https://login.live.com/logout.srf'],
Woot: ['GET', 'https://account.woot.com/logout'],
Wordpress: ['GET', 'https://wordpress.com/wp-login.php?action=logout'],
Yahoo: ['GET', 'https://login.yahoo.com/config/login?.src=fpctx&logout=1&.direct=1&.done=https://www.yahoo.com/'],
YouTube: ['POST', 'https://www.youtube.com', { action_logout: '1' }]
}
/**
* Array to store the child windows spawned by this window.
*/
const wins = []
/**
* Count of number of clicks
*/
let interactionCount = 0
/**
* Number of iframes injected into the page for the "super logout" functionality.
* See superLogout().
*/
let numSuperLogoutIframes = 0
/**
* Is this window a child window? A window is a child window if there exists a
* parent window (i.e. the window was opened by another window so `window.opener`
* is set) *AND* that parent is a window on the same origin (i.e. the window was
* opened by us, not an external website)
*/
const isChildWindow = (window.opener && isParentSameOrigin()) ||
window.location.search.indexOf('child=true') !== -1
/**
* Is this window a parent window?
*/
const isParentWindow = !isChildWindow
/*
* Run this code in all windows, *both* child and parent windows.
*/
init()
/*
* Use `window.opener` to detect if this window was opened by another window, which
* will be its parent. The `window.opener` variable is a reference to the parent
* window.
*/
if (isChildWindow) initChildWindow()
else initParentWindow()
/**
* Initialization code for *both* parent and child windows.
*/
function init () {
confirmPageUnload()
interceptUserInput(event => {
interactionCount += 1
// Prevent default behavior (breaks closing window shortcuts)
event.preventDefault()
event.stopPropagation()
// 'touchstart' and 'touchend' events are not able to open a new window
// (at least in Chrome), so don't even try. Checking `event.which !== 0` is just
// a clever way to exclude touch events.
if (event.which !== 0) openWindow()
startVibrateInterval()
enablePictureInPicture()
triggerFileDownload()
focusWindows()
copySpamToClipboard()
speak()
startTheramin()
// Capture key presses on the Command or Control keys, to interfere with the
// "Close Window" shortcut.
if (event.key === 'Meta' || event.key === 'Control') {
window.print()
requestWebauthnAttestation()
window.print()
requestWebauthnAttestation()
window.print()
requestWebauthnAttestation()
} else {
requestPointerLock()
requestFullscreen()
requestClipboardRead()
requestMidiAccess()
requestBluetoothAccess()
requestUsbAccess()
requestSerialAccess()
requestHidAccess()
requestCameraAndMic()
if (Math.random() < 0.1) {
// Don't request TouchID on every interaction in Safari since it blocks
// the event loop and stops windows from moving
requestWebauthnAttestation()
}
}
})
}
/**
* Initialization code for child windows.
*/
function initChildWindow () {
registerProtocolHandlers()
hideCursor()
moveWindowBounce()
setupFollowWindow()
startVideo()
detectWindowClose()
triggerFileDownload()
speak()
rainbowThemeColor()
animateUrlWithEmojis()
interceptUserInput(event => {
if (interactionCount === 1) {
startAlertInterval()
}
})
}
/**
* Initialization code for parent windows.
*/
function initParentWindow () {
showHelloMessage()
blockBackButton()
fillHistory()
startInvisiblePictureInPictureVideo()
interceptUserInput(event => {
// Only run these on the first interaction
if (interactionCount === 1) {
registerProtocolHandlers()
attemptToTakeoverReferrerWindow()
hideCursor()
startVideo()
startAlertInterval()
superLogout()
removeHelloMessage()
rainbowThemeColor()
animateUrlWithEmojis()
speak('That was a mistake')
}
})
}
/**
* Sites that link to theannoyingsite.com may specify `target='_blank'` to open the
* link in a new window. For example, Messenger.com from Facebook does this.
* However, that means that `window.opener` will be set, which allows us to redirect
* that window. YES, WE CAN REDIRECT THE SITE THAT LINKED TO US.
* Learn more here: https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/
*/
function attemptToTakeoverReferrerWindow () {
if (isParentWindow && window.opener && !isParentSameOrigin()) {
window.opener.location = `${window.location.origin}/?child=true`
}
}
/**
* Returns true if the parent window is on the same origin. It's not enough to check
* that `window.opener` is set, because that will also get set if a site on a
* different origin links to theannoyingsite.com with `target='_blank'`.
*/
function isParentSameOrigin () {
try {
// May throw an exception if `window.opener` is on another origin
return window.opener.location.origin === window.location.origin
} catch (err) {
return false
}
}
/**
* Ask the user "are you sure you want to leave this page?". In most browsers,
* this will not actually do anything unless the user has at least one interaction
* with the page before they close it.
*/
function confirmPageUnload () {
window.addEventListener('beforeunload', event => {
speak('Please don\'t go!')
event.returnValue = true
})
}
/**
* Attempt to register all possible browser-whitelisted protocols to be handled by
* this web app instead of their default handlers.
*/
function registerProtocolHandlers () {
if (typeof navigator.registerProtocolHandler !== 'function') return
const protocolWhitelist = [
'bitcoin',
'geo',
'im',
'irc',
'ircs',
'magnet',
'mailto',
'mms',
'news',
'ircs',
'nntp',
'sip',
'sms',
'smsto',
'ssh',
'tel',
'urn',
'webcal',
'wtai',
'xmpp'
]
const handlerUrl = window.location.href + '/url=%s'
protocolWhitelist.forEach(proto => {
navigator.registerProtocolHandler(proto, handlerUrl, 'The Annoying Site')
})
}
/**
* Attempt to access the user's camera and microphone, and attempt to enable the
* torch (i.e. camera flash) if the device has one.
*/
function requestCameraAndMic () {
if (!navigator.mediaDevices ||
typeof navigator.mediaDevices.getUserMedia !== 'function') {
return
}
navigator.mediaDevices.enumerateDevices().then(devices => {
const cameras = devices.filter((device) => device.kind === 'videoinput')
if (cameras.length === 0) return
const camera = cameras[cameras.length - 1]
navigator.mediaDevices.getUserMedia({
deviceId: camera.deviceId,
facingMode: ['user', 'environment'],
audio: true,
video: true
}).then(stream => {
const track = stream.getVideoTracks()[0]
const imageCapture = new window.ImageCapture(track)
imageCapture.getPhotoCapabilities().then(() => {
// Let there be light!
track.applyConstraints({ advanced: [{ torch: true }] })
}, () => { /* No torch on this device */ })
}, () => { /* ignore errors */ })
})
}
/**
* Animating the URL with emojis
* See: https://matthewrayfield.com/articles/animating-urls-with-javascript-and-emojis/
*/
function animateUrlWithEmojis () {
if (window.ApplePaySession) {
// Safari doesn't show the full URL anyway, so we can't animate it
return
}
const rand = Math.random()
if (rand < 0.33) {
animateUrlWithBabies()
} else if (rand < 0.67) {
animateUrlWithWave()
} else {
animateUrlWithMoons()
}
function animateUrlWithBabies () {
const e = ['🏻', '🏼', '🏽', '🏾', '🏿']
setInterval(() => {
let s = ''
let i; let m
for (i = 0; i < 10; i++) {
m = Math.floor(e.length * ((Math.sin((Date.now() / 100) + i) + 1) / 2))
s += '👶' + e[m]
}
window.location.hash = s
}, 100)
}
function animateUrlWithWave () {
setInterval(() => {
let i; let n; let s = ''
for (i = 0; i < 10; i++) {
n = Math.floor(Math.sin((Date.now() / 200) + (i / 2)) * 4) + 4
s += String.fromCharCode(0x2581 + n)
}
window.location.hash = s
}, 100)
}
function animateUrlWithMoons () {
const f = ['🌑', '🌘', '🌗', '🌖', '🌕', '🌔', '🌓', '🌒']
const d = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let m = 0
setInterval(() => {
let s = ''
let x = 0
if (!m) {
while (d[x] === 4) {
x++
}
if (x >= d.length) m = 1
else {
d[x]++
}
} else {
while (d[x] === 0) {
x++
}
if (x >= d.length) m = 0
else {
d[x]++
if (d[x] === 8) d[x] = 0
}
}
d.forEach(function (n) {
s += f[n]
})
window.location.hash = s
}, 100)
}
}
/**
* Lock the user's pointer, without even being in full screen!
* Require user-initiated event.
*/
function requestPointerLock () {
const requestPointerLockApi = (
document.body.requestPointerLock ||
document.body.webkitRequestPointerLock ||
document.body.mozRequestPointerLock ||
document.body.msRequestPointerLock
)
requestPointerLockApi.call(document.body)
}
/**
* Start vibrating the device at random intervals, on supported devices.
* Requires user-initiated event.
*/
function startVibrateInterval () {
if (typeof window.navigator.vibrate !== 'function') return
setInterval(() => {
const duration = Math.floor(Math.random() * 600)
window.navigator.vibrate(duration)
}, 1000)
// If the gamepad can vibrate, we will at random intervals every second. And at random strengths!
window.addEventListener('gamepadconnected', (event) => {
const gamepad = event.gamepad
if (gamepad.vibrationActuator) {
setInterval(() => {
if (gamepad.connected) {
gamepad.vibrationActuator.playEffect('dual-rumble', {
duration: Math.floor(Math.random() * 600),
strongMagnitude: Math.random(),
weakMagnitude: Math.random()
})
}
}, 1000)
}
})
}
/**
* Intercept all user-initiated events and call the given the function, `onInput`.
*/
function interceptUserInput (onInput) {
document.body.addEventListener('touchstart', onInput, { passive: false })
document.body.addEventListener('mousedown', onInput)
document.body.addEventListener('mouseup', onInput)
document.body.addEventListener('click', onInput)
document.body.addEventListener('keydown', onInput)
document.body.addEventListener('keyup', onInput)
document.body.addEventListener('keypress', onInput)
}
/**
* Start an invisible, muted video so we have a one ready to put into
* picture-in-picture mode on the first user-interaction.
*/
function startInvisiblePictureInPictureVideo () {
const video = document.createElement('video')
video.src = getRandomArrayEntry(VIDEOS)
video.loop = true
video.muted = true
video.style = HIDDEN_STYLE
video.autoplay = true
video.play()
document.body.appendChild(video)
}
/**
* Active Safari's picture-in-picture feature, which let's show a video on the
* desktop. Requires user-initiated event.
*/
function enablePictureInPicture () {
const video = document.querySelector('video')
if (document.pictureInPictureEnabled) {
video.style = ''
video.muted = false
video.requestPictureInPicture()
video.play()
}
}
/**
* Focus all child windows. Requires user-initiated event.
*/
function focusWindows () {
wins.forEach(win => {
if (!win.closed) win.focus()
})
}
/**
* Open a new popup window. Requires user-initiated event.
*/
function openWindow () {
const { x, y } = getRandomCoords()
const opts = `width=${WIN_WIDTH},height=${WIN_HEIGHT},left=${x},top=${y}`
const win = window.open(window.location.pathname, '', opts)
// New windows may be blocked by the popup blocker
if (!win) return
wins.push(win)
if (wins.length === 2) setupSearchWindow(win)
}
/**
* Hide the user's cursor!
*/
function hideCursor () {
document.querySelector('html').style = 'cursor: none;'
}
/**
* Trigger a file download immediately. One file download is allowed *without* user
* interaction. Further file downloads should happen in response to a user-initiated
* event or they will be blocked.
*/
function triggerFileDownload () {
const fileName = getRandomArrayEntry(FILE_DOWNLOADS)
const a = document.createElement('a')
a.href = fileName
a.download = fileName
a.click()
}
/**
* Speak the given `phrase` using text-to-speech.
*/
function speak (phrase) {
if (phrase == null) phrase = getRandomArrayEntry(PHRASES)
window.speechSynthesis.speak(new window.SpeechSynthesisUtterance(phrase))
}
/**
* Start an annoying theramin that changes pitch and volume depending on
* the mouse position. Uses a Web Audio oscillator. Reauires user-initiated
* event.
* Based on https://github.com/feross/TheAnnoyingSite.com/pull/2
*/
function startTheramin () {
const audioContext = new AudioContext()
const oscillatorNode = audioContext.createOscillator()
const gainNode = audioContext.createGain()
const pitchBase = 50
const pitchRange = 4000
const wave = audioContext.createPeriodicWave(
Array(10).fill(0).map((v, i) => Math.cos(i)),
Array(10).fill(0).map((v, i) => Math.sin(i))
)
oscillatorNode.setPeriodicWave(wave)
oscillatorNode.connect(gainNode)
gainNode.connect(audioContext.destination)
oscillatorNode.start(0)
const oscillator = ({ pitch, volume }) => {
oscillatorNode.frequency.value = pitchBase + pitch * pitchRange
gainNode.gain.value = volume * 0.5
}
document.body.addEventListener('mousemove', event => {
const { clientX, clientY } = event
const { clientWidth, clientHeight } = document.body
const pitch = (clientX - clientWidth / 2) / clientWidth
const volume = (clientY - clientHeight / 2) / clientHeight
oscillator({ pitch, volume })
})
}
/**
* Attempt to read the user's clipboard.
* Requires user-initiated event.
*/
function requestClipboardRead () {
try {
navigator.clipboard.readText().then(
data => {
if (!window.ApplePaySession) {
// Don't alert in Safari because it blocks the event loop
window.alert("Successfully read data from clipboard: '" + data + "'")
}
},
() => {}
)
} catch {}
}
/**
* Request Webauthn attestation.
* Requires user-initiated event.
*/
function requestWebauthnAttestation () {
try {
// From https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API
// This code is public domain, per https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses
// sample arguments for registration
const createCredentialDefaultArgs = {
publicKey: {
// Relying Party (a.k.a. - Service):
rp: {
name: 'Acme'
},
// User:
user: {
id: new Uint8Array(16),
name: 'YOU_ARE_HACKED@THEANNOYINGSITE.COM',
displayName: 'YOU ARE HACKED'
},
pubKeyCredParams: [{
type: 'public-key',
alg: -7
}],
attestation: 'direct',
timeout: 60000,
challenge: new Uint8Array([ // must be a cryptographically random number sent from a server
0x8C, 0x0A, 0x26, 0xFF, 0x22, 0x91, 0xC1, 0xE9, 0xB9, 0x4E, 0x2E, 0x17, 0x1A, 0x98, 0x6A, 0x73,
0x71, 0x9D, 0x43, 0x48, 0xD5, 0xA7, 0x6A, 0x15, 0x7E, 0x38, 0x94, 0x52, 0x77, 0x97, 0x0F, 0xEF
]).buffer
}
}
// sample arguments for login
const getCredentialDefaultArgs = {
publicKey: {
timeout: 60000,
// allowCredentials: [newCredential] // see below
challenge: new Uint8Array([ // must be a cryptographically random number sent from a server
0x79, 0x50, 0x68, 0x71, 0xDA, 0xEE, 0xEE, 0xB9, 0x94, 0xC3, 0xC2, 0x15, 0x67, 0x65, 0x26, 0x22,
0xE3, 0xF3, 0xAB, 0x3B, 0x78, 0x2E, 0xD5, 0x6F, 0x81, 0x26, 0xE2, 0xA6, 0x01, 0x7D, 0x74, 0x50
]).buffer
}
}
// register / create a new credential
navigator.credentials.create(createCredentialDefaultArgs)
.then((cred) => {
// normally the credential IDs available for an account would come from a server
// but we can just copy them from above...
const idList = [{
id: cred.rawId,
transports: ['usb', 'nfc', 'ble'],
type: 'public-key'
}]
getCredentialDefaultArgs.publicKey.allowCredentials = idList
return navigator.credentials.get(getCredentialDefaultArgs)
})
} catch {}
}
/**
* Request access to MIDI devices.
* Requires user-initiated event.
*/
function requestMidiAccess () {
try {
navigator.requestMIDIAccess({
sysex: true
})
} catch {}
}
/**
* Request access to Bluetooth devices.
* Requires user-initiated event.
*/
function requestBluetoothAccess () {
try {
navigator.bluetooth.requestDevice({
// filters: [...] <- Prefer filters to save energy & show relevant devices.
// acceptAllDevices here ensures dialog can populate, we don't care with what.
acceptAllDevices: true
})
.then(device => device.gatt.connect())
} catch {}
}
/**
* Request access to USB devices.
* Requires user-initiated event.
*/
function requestUsbAccess () {
try {
navigator.usb.requestDevice({ filters: [{}] })
} catch {}
}
/**
* Request access to Serial devices.
* Requires user-initiated event.
*/
function requestSerialAccess () {
try {
navigator.serial.requestPort({ filters: [] })
} catch {}
}
/**
* Request access to HID devices.
* Requires user-initiated event.
*/
function requestHidAccess () {
try {
navigator.hid.requestDevice({ filters: [] })
} catch {}
}
/**
* Move the window around the screen and bounce off of the screen edges.
*/
function moveWindowBounce () {
let vx = VELOCITY * (Math.random() > 0.5 ? 1 : -1)
let vy = VELOCITY * (Math.random() > 0.5 ? 1 : -1)
setInterval(() => {
const x = window.screenX
const y = window.screenY
const width = window.outerWidth
const height = window.outerHeight
if (x < MARGIN) vx = Math.abs(vx)
if (x + width > SCREEN_WIDTH - MARGIN) vx = -1 * Math.abs(vx)
if (y < TOP_MARGIN) vy = Math.abs(vy)
if (y + height > SCREEN_HEIGHT - MARGIN) vy = -1 * Math.abs(vy)
window.moveBy(vx, vy)
}, TICK_LENGTH)
}
/**
* Follow the user's mouse
*/
function setupFollowWindow () {
document.addEventListener('mousemove', function (e) {
window.moveTo(e.screenX - (WIN_WIDTH / 2), e.screenY - (WIN_HEIGHT / 2))
})
}
/**
* Show a random troll video in the window.
*/
function startVideo () {
const video = document.createElement('video')
video.src = getRandomArrayEntry(VIDEOS)
video.autoplay = true
video.loop = true
video.style = 'width: 100%; height: 100%;'
document.body.appendChild(video)
}
/**
* When a child window closes, notify the parent window so it can remove it from
* the list of child windows.
*/
function detectWindowClose () {
window.addEventListener('unload', () => {
if (!window.opener.closed) window.opener.onCloseWindow(window)
})
}
/**
* Handle a child window closing.
*/
function onCloseWindow (win) {
const i = wins.indexOf(win)
if (i >= 0) wins.splice(i, 1)
}
/**
* Show the unsuspecting user a friendly hello message with a cat.
*/
function showHelloMessage () {
const template = document.querySelector('template')
const clone = document.importNode(template.content, true)
document.body.appendChild(clone)
}
/**
* Remove the hello message.
*/
function removeHelloMessage () {
const helloMessage = document.querySelector('.hello-message')
helloMessage.remove()
}
/**
* Change the theme color of the browser in a loop.
*/
function rainbowThemeColor () {
function zeroFill (width, number, pad = '0') {
width -= number.toString().length
if (width > 0) return new Array(width + (/\./.test(number) ? 2 : 1)).join(pad) + number
return number + ''
}
const meta = document.querySelector('meta.theme-color')
setInterval(() => {
meta.setAttribute('content', '#' + zeroFill(6, Math.floor(Math.random() * 16777215).toString(16)))
}, 50)
}
/**
* Copy cat pictures onto the user's clipboard. Requires user-initiated event.
*/
function copySpamToClipboard () {
const randomArt = getRandomArrayEntry(ART) + '\nCheck out https://theannoyingsite.com'
clipboardCopy(randomArt)
}
/**
* Copy given text, `text`, onto the user's clipboard.
* Requires user-initiated event.
*/
function clipboardCopy (text) {
// A <span> contains the text to copy
const span = document.createElement('span')
span.textContent = text
span.style.whiteSpace = 'pre' // Preserve consecutive spaces and newlines
// An <iframe> isolates the <span> from the page's styles
const iframe = document.createElement('iframe')
iframe.sandbox = 'allow-same-origin'
document.body.appendChild(iframe)
let win = iframe.contentWindow
win.document.body.appendChild(span)
let selection = win.getSelection()
// Firefox fails to get a selection from <iframe> window, so fallback
if (!selection) {
win = window
selection = win.getSelection()
document.body.appendChild(span)
}
const range = win.document.createRange()
selection.removeAllRanges()
range.selectNode(span)
selection.addRange(range)
let success = false
try {
success = win.document.execCommand('copy')
} catch (err) {
console.log(err)
}
selection.removeAllRanges()
span.remove()
iframe.remove()
return success
}
/**
* Show a modal dialog at a regular interval. Modals capture focus from other OS apps and browser tabs.
* Except in Chrome 64+, where modals can only capture focus from other OS apps,
* but not from other tabs.
*/
function startAlertInterval () {
setInterval(() => {
if (Math.random() < 0.5) {
showAlert()
} else {
window.print()
}
}, 120_000)
}
/**
* Show an alert with 1000's of lines of cat ASCII art.
*/
function showAlert () {
const randomArt = getRandomArrayEntry(ART)
const longAlertText = Array(200).join(randomArt)
window.alert(longAlertText)
}
/**
* Fullscreen the browser window
*/
function requestFullscreen () {
const requestFullscreen = Element.prototype.requestFullscreen ||
Element.prototype.webkitRequestFullscreen ||
Element.prototype.mozRequestFullScreen ||
Element.prototype.msRequestFullscreen
requestFullscreen.call(document.body)
}