forked from rslashplace2/rslashplace2.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
posts.html
674 lines (661 loc) · 31.1 KB
/
posts.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>posts</title>
<link href="rplace-2022.css?v=11" rel="stylesheet">
<link href="style.css?v=350" rel="stylesheet">
<link href="posts.css?v=1" rel="stylesheet">
<script type="application/javascript" src="elements.js?v=6" defer></script>
<script id="postsManager" type="application/javascript" src="posts-manager.js?v=5" defer></script>
<script type="application/javascript" src="shared.js?v=2"></script>
<script>
WebSocket.prototype.send = function(){this.close()}; document.execCommand = (_) => {window.location.reload(true)};
const I=HTMLIFrameElement.prototype; delete I.contentWindow;delete I.contentDocument;
delete I.getSVGDocument; delete eval; delete Function.prototype.constructor; delete Function; delete Worker; delete WebSocket;
</script>
</head>
<body>
<header>
<div class="header-title-container">
<button type="button" class="header-menu" onclick="openSidebar()">
<img src="./svg/menu.svg" alt="Menu" width="36" height="36">
</button>
<img src="./images/rplace.png" class="header-icon" alt="Rplace logo">
<h1 class="header-title" translate="rplaceLivePosts">rplace.live posts</h1>
</div>
<input id="postsSearchbar" type="text" class="post-input searchbar" translate="searchKeyword" placeholder="Search keyword" onchange="
const keyword = this.value.trim().toLowerCase()
if (keyword) {
tryLoadKeywordPosts(keyword)
this.dataset.searching = 'true'
}
else {
this.dataset.searching = 'false'
clearPosts()
tryLoadBottomPosts()
}">
<div><!--Spacer--></div>
</header>
<div id="sidebar" class="sidebar">
<a type="button" href="./posts.html" style="column-gap: 8px;">
<svg fill="currentColor" icon-name="home-fill" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" width="24" height="24">
<path d="m19.724 6.765-9.08-6.11A1.115 1.115 0 0 0 9.368.647L.276 6.765a.623.623 0 0 0 .35 1.141h.444v10.001c.001.278.113.544.31.74.196.195.462.304.739.303h5.16a.704.704 0 0 0 .706-.707v-4.507c0-.76 1.138-1.475 2.02-1.475.882 0 2.02.715 2.02 1.475v4.507a.71.71 0 0 0 .707.707h5.16c.274-.001.538-.112.732-.307.195-.195.305-.46.306-.736v-10h.445a.618.618 0 0 0 .598-.44.625.625 0 0 0-.25-.702Z"></path>
</svg>
Posts
</a>
<a type="button" href="./">
<img src="svg/rplace.svg" width="24" height="24">
Game
</a>
<div class="sidebar-footer">
<a href="https://rplace.live">rplace.live</a> |
<a href="./disclaimer.html">disclaimer</a> |
<a href="https://github.com/rplacetk">github</a>
</div>
</div>
<div id="sidebarBackground" class="sidebar-background"></div>
<div id="contents">
<div class="posts-side-panel">
<div class="posts-extern-buttons">
<button type="button" id="postJumpButton" class="posts-button posts-jump-button" onclick="communityPostsPost.scrollIntoView({ behavior: 'smooth', block: 'start' })">
<svg title="Change channel" style="vertical-align: bottom;" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24">
<path d="M480-345 240-585l43-43 197 198 197-197 43 43-240 239Z"></path>
</svg>Jump to community posts
</button>
<a type="button" style="column-gap: 4px" class="posts-button" href="#" onclick="event.preventDefault(); sendParentMessage('open', './posts.html')">
<img alt="Expand" src="./svg/expand-external.svg" width="24" height="24"> See more
</a>
</div>
</div>
<div id="createPostPost" class="post" style="padding-left: 15px; cursor: default;" ondragenter="
event.stopPropagation()
event.preventDefault()
" ondragover="
event.stopPropagation()
event.preventDefault()
this.classList.add('image-drop')
" ondrop="
event.stopPropagation()
event.preventDefault()
this.classList.remove('image-drop')
for (const file of event.dataTransfer.files) {
if (file.type.startsWith('image/')) {
createPostContent.addContent(file)
}
}
" ondragleave="
event.stopPropagation()
event.preventDefault()
this.classList.remove('image-drop')
">
<div class="create-post-image-drop">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24">
<path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h360v80H200v560h560v-360h80v360q0 33-23.5 56.5T760-120H200Zm480-480v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80ZM240-280h480L570-480 450-320l-90-120-120 160Zm-40-480v560-560Z"/>
</svg>
<span>Upload image</span>
</div>
<div class="create-post-body">
<div class="create-post-account-button">
<img src="./svg/account.svg" alt="Account icon" width="32" height="32">
</div>
<div class="create-post-inputs-container">
<input type="text" id="createPostTitle" minlength="1" maxlength="64" required class="create-post-input create-post-extra" placeholder="Post title..." onchange="
createPostTitle.value = createPostTitle.value.trim()
const validityState = createPostTitle.validity
if (validityState.tooLong || validityState.tooShort || validityState.valueMissing) {
createPostTitle.setCustomValidity('Post title should be between 1-64 characters long!')
}
else {
createPostTitle.setCustomValidity('')
}
createPostTitle.reportValidity()
">
<textarea id="createPostInput" maxlength="360" class="create-post-input" placeholder="Create post..."
onkeypress="event.stopPropagation()"
onfocus="
createPostPost.classList.add('focused')
createPostInput.placeholder = 'Post content...'
"></textarea>
</div>
<button class="create-post-content-button" onclick="createPostContentInput.click()">
<img src="./svg/image.svg" alt="Add post attachment" width="32" height="32">
</button>
<input type="file" id="createPostContentInput" accept="image/gif,image/jpeg,image/png,image/webp" onchange="
for (const file of this.files) {
createPostContent.addContent(file)
}
" style="display: none;">
</div>
<div id="createPostOptions" class="create-post-extra">
<r-post-contents-preview id="createPostContent"></r-post-contents-preview>
<div class="create-post-create-discard">
<button id="discardPostButton" type="button" class="post-button discard-post-button" onclick="resetCreatePost()">Discard</button>
<button id="createPostButton" type="button" class="post-button create-post-button" onclick="
async function uploadAndUpdatePosts() {
discardPostButton.disabled = true
createPostButton.disabled = true
const progressCb = function(stage, info) {
if (stage == 'uploadPost') {
createPostStatus.textContent = 'Uploading post: ' + `${info.progress}%`
}
else if (stage == 'uploadContent') {
createPostStatus.textContent = 'Uploading attachment...' + `(${info.current}/${info.total})`
}
}
if (await uploadPost(createPostTitle.value, createPostInput.value, createPostContent.contents, progressCb)) {
resetCreatePost()
alert('Post success!')
await tryLoadTopPosts()
}
else {
createPostStatus.textContent = ''
createPostButton.disabled = false
discardPostButton.disabled = false
}
}
if (!createPostTitle.checkValidity()) {
createPostTitle.reportValidity()
return
}
if (!localStorage.agredPostRules) {
sendParentMessage('scrollToPosts')
postRulesDialog.showModal()
postRulesDialog.onclose = function(e) {
if (postRulesDialog.returnValue === true) {
uploadAndUpdatePosts()
}
}
}
else {
uploadAndUpdatePosts()
}
">Post</button>
</div>
<span id="createPostStatus" class="create-post-status"></span>
</div>
</div>
<div id="liveChatPost" onclick="sendParentMessage('openChatPanel')" class="post" style="cursor: pointer;" novotes="true">
<img alt="Live chat icon" class="cover-image" src="images/live.png">
<div class="body">
<div class="main">
<div class="title" translate="liveChat">Live Chat</div>
<span class="description" id="onlineCounter2">... online</span>
</div>
</div>
</div>
<div id="mainCanvasPost" class="post" style="cursor: pointer;" novotes="true">
<img alt="Rplace logo" class="cover-image" src="images/rplace.png">
<div class="body">
<div class="main">
<div class="title">Main Canvas</div>
<div class="description">750x750 (cooldown: 800ms)</div>
</div>
</div>
<r-clipboard-copy title="Copy canvas URL to clipbaord" src="https://rplace.live/?server=wss://server.rplace.live:443&board=https://raw.githubusercontent.com/rplacetk/canvas1/main/place"></r-clipboard-copy>
</div>
<!--<r-post onclick="window.open('https:\/\/lamda.count.land/', '_blank')" class="post" novotes="true" title="Lamda" description="Chat anonymously with strangers online. Start random voice calls and meet others!"
coverimageurl="images/lamda.png"></r-post>
<r-post onclick="toggleTlPanel()" class="post" style="opacity: 0.6; pointer-events: none;" novotes="true" title="Timelapse tool" description="Combine a sequence from the history of the canvas to create your own timelapse video!"
coverimageurl="images/timelapse.png"></r-post>-->
<r-post id="overlayPost" onclick="sendParentMessage('openOverlayMenu')" style="cursor: pointer;" class="post" novotes="true" title="Overlay menu" description="Visualise your build with template images!"
coverimageurl="images/hammer-and-wrench.png"></r-post>
<r-post onclick="window.open('https:\/\/discord.gg/r-place-2-960966748289507338','_blank')" style="cursor: pointer;" class="post" novotes="true" title="Discord" description="discord.gg/r-place-2-960966748289507338"
coverimageurl="images/discord.png"></r-post>
<r-post onclick="window.open('https:\/\/bit.ly/3LVwDtW','_blank')" style="cursor: pointer;" class="post" novotes="true" title="Donate" description="Help keep r/place alive!"
coverimageurl="images/patreon.png"></r-post>
<r-post onclick="window.open('https:/\/reddit.com/r/placetk','_blank')" style="cursor: pointer;" class="post" novotes="true" title="Subreddit" description="Visit the official rplace.live subreddit (r/placetk)"
coverimageurl="images/reddit.png"></r-post>
<r-post onclick="window.open('https:\/\/rplacetk.github.io\/colour-utils\/','_blank')" style="cursor: pointer;" class="post" novotes="true" title="Colour utils" description="A collection of nifty utilities to work with rplace.live canvases"
coverimageurl="images/colour-utils.png"></r-post>
<!--<r-post onclick="accountDialog.showModal(); unauthedPage.dataset.page = 'signin';" class="post" style="opacity: 0.6; pointer-events: none;" novotes="true" title="My Account" description="Login or signup to an rplace.live account, access special features and host your own custom canvases"
coverimageurl="images/account-profile.png"></r-post>-->
<r-post onclick="window.open('https:\/\/canv.tk/', '_blank')" style="cursor: pointer;" class="post" novotes="true" title="Canv.tk" description="Visit our sister site, the proof of concept this site itself was built off, canv.tk here!"
coverimageurl="images/canv.png"></r-post>
<div id="communityPostsPost" class="post" novotes="true">
<div class="body">
<div class="horizontal-labeled-separator header">
<hr>
<span>Community posts</span>
<hr>
</div>
<div style="display: flex; column-gap: 16px; align-items: center; justify-content: center;">
<label for="postsSortSelect" translate="sortBy">Sort by:</label>
<select id="postsSortSelect" style="box-shadow: none; border-radius: 64px; background: white;">
<option value="date" translate="date">Date</option>
<option value="upvotes" translate="upvotes">Upvotes</option>
</select>
<label for="postsHideSensitive" translate="hideSensitive">Hide sensitive:</label>
<input id="postsHideSensitive" type="checkbox" checked style="box-shadow: none; border-radius: 64px;">
</div>
</div>
</div>
</div>
<dialog id="postRulesDialog" class="reddit-modal">
<r-close-icon onclick="postRulesDialog.close()" style="position: absolute; top: 10px; right: 10px; z-index: 1;"></r-close-icon>
<div style="display: flex; flex-direction: column; padding: 16px; overflow-y: scroll; row-gap: 8px;">
<h4>By creating a post, you agree to the following conditions:</h4>
<ol style="font-size: 18px;line-height: 32px;margin-left: 16px; flex-grow: 1;">
<li>All posts you create are public, and any information shared in a post will be visible to everyone.</li>
<li>Your post must be related to rplace and must not contain NSFW or copyrighted content.</li>
<li>All content uploaded may be processed by third party content filters and AI detection systems.</li>
<li>Illegal content shall not be posted, and will be reported to relevant authorities, alongside any necessary user information to aid with investigation.</li>
</ol>
<img src="images/example-post.png" alt="Example post" style="height: 256px;object-fit: contain;">
<button class="reddit-modal-button" onclick="
localStorage.agredPostRules = true
postRulesDialog.close(true)
">Create post</button>
</div>
</dialog>
<dialog id="accountDialog" class="reddit-modal">
<div id="loginPanel" data-page="unauthed">
<div class="header">
<h4 style="margin: 0px;">My account</h4>
</div>
<r-close-icon onclick="accountDialog.close()" class="active" style="position: absolute; top: 10px; right: 10px;"></r-close-icon>
<div id="unauthedPage" class="body" page="unauthed" data-page="signin">
<div id="signinPage" class="body" page="signin">
<h4>Sign in</h4>
<input type="text" class="reddit-modal-input" placeholder="Username*" id="loginUsername" maxlength="32" minlength="4">
<input type="email" class="reddit-modal-input" placeholder="Email*" id="loginEmail">
<button type="button" class="reddit-modal-button" id="signinButton" onclick="
unauthedPage.dataset.page = 'authcode'
">Continue</button>
</div>
<div id="signupPage" class="body" page="signup">
<h4>Sign up</h4>
<input type="text" class="reddit-modal-input" placeholder="Username*" id="signupUsername" maxlength="32" minlength="4">
<input type="email" class="reddit-modal-input" placeholder="Email*" id="signupEmail" required>
<input type="email" class="reddit-modal-input" placeholder="Confirm email*" id="signupEmailConfirm" required>
<button type="button" class="reddit-modal-button" id="signupButton">Continue</button>
<span id="loginSignupMessage"></span>
</div>
<div id="authCodePage" class="body" page="authcode">
<div style="display: flex;align-items: center; column-gap: 8px; margin-bottom: 10px;">
<button type="button" onclick="unauthedPage.dataset.page='signin'" style="display: inline; background: transparent; padding: 0px; box-shadow: none;">
<image src="svg/icon-back.svg"></image>
</button>
<h3 style="display: inline-block;">Email verification</h3>
</div>
<h4>If you're lucky, an email has been sent to your inbox</h4>
<p>Enter the code sent below to authenticate your account</p>
<div style="display: flex;align-items: center;align-content: center;">
<input type="text"><input type="text"><input type="text"><input type="text"><input type="text"><input type="text">
</div>
<input type="text" class="reddit-modal-input" placeholder="Authentication code*" id="authCode" autocomplete="off" minlength="10">
<button type="button" class="reddit-modal-button" id="authCodeButton">Submit</button>
</div>
<div style="flex-grow: 1"></div>
<h4>Other options:</h4>
<div style="display: flex;column-gap: 8px;margin: 8px;">
<button type="button" class="reddit-signin-button" noselect disabled onclick="
const csrf = (Math.random() + 1).toString(36).substring(2)
window.open('https:\/\/www.reddit.com/api/v1/authorize?client_id=eqjRPVmD2M7InsCDhBdvVg&response_type=code'
+ '&state='+csrf+'&redirect_uri=https:\/\/rplace.live/&duration=permanent&scope=identity')
window.close()
">
<img src="images/reddit.png" style="height: 100%;"><span style="align-self: center;">Sign in with reddit</span>
</button>
<a href="#" ontouchend="event.preventDefault(); this.click()" onclick="{
event.preventDefault()
let isSigninPage = unauthedPage.dataset.page === 'signin'
unauthedPage.dataset.page = isSigninPage ? 'signup' : 'signin'
//this.textContent = translate(isSigninPage ? 'signInInstead' : 'createNewAccount')
}" style="align-self: center;" translate="createNewAccount">Create a new account</a>
</div>
</div>
<div class="body" style="display: none;overflow-y: scroll;" data-page="profile">
<h4 style="margin-bottom: 8px;">🔑 Sucessfully logged in as <span id="profileName2"></span></h4>
<r-close-icon onclick="loginPanel.style.display = 'none'" style="position: absolute; top: 10px; right: 10px;"></r-close-icon>
<div style="flex-grow: 1">
<h4>Profile</h4>
<div class="reddit-card">
<img id="profileImg" src="https://static.vecteezy.com/system/resources/thumbnails/009/292/244/small/default-avatar-icon-of-social-media-user-vector.jpg">
<div class="profile-section" style="min-width: 164px;">
<p id="profileName"></p>
<div profileeditable noselect onmouseleave="profileDiscordEdit.style.display = 'none'">
<img width="16" height="16" src="images/discord.png" id="profileDiscordIcon">
<span>Discord: </span><a id="profileDiscord" href=""></a>
<span onclick="profileDiscordEdit.style.display = profileDiscordEdit.style.display == 'none' ? 'block' : 'none'">
<svg xmlns="http://www.w3.org/2000/svg" style="opacity: 0.2;cursor:pointer;" height="16" viewBox="0 96 960 960" width="16">
<path d="M180 876h44l443-443-44-44-443 443v44Zm614-486L666 262l42-42q17-17 42-17t42 17l44 44q17 17 17 42t-17 42l-42 42Zm-42 42L248 936H120V808l504-504 128 128Zm-107-21-22-22 44 44-22-22Z"/>
</svg>
</span>
<div id="profileDiscordEdit" style="display: none">
<input type="text" class="reddit-modal-input" placeholder="Discord Snowflake/ID" id="profileDiscordInput">
<button type="button" class="reddit-modal-button" style="padding: 6px;" id="profileDiscordSubmit">Update</button>
</div>
</div>
<div profileeditable noselect onmouseleave="profileTwitterEdit.style.display = 'none'">
<img width="16" height="16" src="images/twitter.png">
<span>Twitter: </span><a id="profileTwitter" href=""></a>
<span onclick="profileTwitterEdit.style.display = profileTwitterEdit.style.display == 'none' ? 'block' : 'none'">
<svg xmlns="http://www.w3.org/2000/svg" style="opacity: 0.2;cursor:pointer;" height="16" viewBox="0 96 960 960" width="16">
<path d="M180 876h44l443-443-44-44-443 443v44Zm614-486L666 262l42-42q17-17 42-17t42 17l44 44q17 17 17 42t-17 42l-42 42Zm-42 42L248 936H120V808l504-504 128 128Zm-107-21-22-22 44 44-22-22Z"/>
</svg>
</span>
<div id="profileTwitterEdit" style="display: none">
<input type="text" class="reddit-modal-input" placeholder="Twitter username" id="profileTwitterInput">
<button type="button" class="reddit-modal-button" style="padding: 6px;" id="profileTwitterSubmit">Update</button>
</div>
</div>
<div profileeditable noselect onmouseleave="profileRedditEdit.style.display = 'none';">
<img width="16" height="16" src="images/reddit.png" id="profileRedditIcon">
<span>Reddit: </span><a id="profileReddit" href=""></a>
<span onclick="profileRedditEdit.style.display = profileRedditEdit.style.display == 'none' ? 'block' : 'none'">
<svg xmlns="http://www.w3.org/2000/svg" style="opacity: 0.2;cursor:pointer;" height="16" viewBox="0 96 960 960" width="16">
<path d="M180 876h44l443-443-44-44-443 443v44Zm614-486L666 262l42-42q17-17 42-17t42 17l44 44q17 17 17 42t-17 42l-42 42Zm-42 42L248 936H120V808l504-504 128 128Zm-107-21-22-22 44 44-22-22Z"/>
</svg>
</span>
<div id="profileRedditEdit" style="display: none;">
<input type="text" class="reddit-modal-input" placeholder="Reddit username" id="profileRedditInput">
<button type="button" class="reddit-modal-button" style="padding: 6px;" id="profileRedditSubmit">Update</button>
</div>
</div>
</div>
<div style="width: 2px;background-color: #ccc;border-radius: 2px;"></div>
<div class="profile-section">
<p style="font-style: italic;">Stats</p>
<div noselect><span>Pixels placed: </span><span id="profilePixels"></span></div>
<div noselect><span>Join date: </span><span id="profileJoin"></span></div>
<div noselect><span>Badges: </span><span id="profileBadges"></span></div>
</div>
</div>
<h4>Account Data:</h4>
<p>Account Tier: <span id="accountTier"></span></p>
<p>Username: <span id="accountName"></span></p>
<p>Email: <span id="accountEmail"></span></p>
<a href="#">Instances: Go to instance manager</a>
</div>
</div>
</div>
</dialog>
</body>
<script>
// Bidirectional IPC, similar to server.ts - db-worker.ts communication
// Methods called by iframe parent
function onlineCounter(count) {
onlineCounter2.textContent = count + " online"
}
function updateDialogTop(topHeight) {
document.body.style.setProperty("--posts-dialog-top", topHeight + "px")
}
let parentReqId = 0
let parentReqs = new Map()
async function makeParentRequest(messageCall, args = undefined) {
const handle = parentReqId++
const promise = new PublicPromise()
const postCall = { call: messageCall, data: args, handle: handle }
parentReqs.set(handle, promise)
window.parent.postMessage(postCall)
return await promise.promise
}
window.addEventListener("message", async function(event) {
if (!event.origin.startsWith(location.origin)) {
throw new Error("Invalid message origin")
}
const message = event.data
if (message.call) { // Parent window asking to call iframe method
let result = undefined
if (window[message.call]) {
result = await window[message.call](message.data)
}
if (message.handle !== undefined && message.handle !== null) {
window.parent.postMessage({ handle: message.handle, data: result }, location.origin)
}
}
else { // Return value from parent method
parentReqs.get(message.handle)?.resolve(message.data)
}
}, false)
function sendParentMessage(messageCall, args = undefined) {
window.parent.postMessage({ call: messageCall, data: args }, location.origin)
}
// Main
function lerp(from, to, weight) {
return from + weight * (to - from)
}
let sidebarDragLastX = 0, sidebarDragStartX = 0, sidebarDragStartY = 0,
sidebarOpen = false, sidebarDrag = 0, sidebarDragging = false
function openSidebar() {
sidebarOpen = true
sidebarDragging = false
transitionSidebar()
}
function closeSidebar() {
sidebarOpen = false
sidebarDrag = 0
sidebarDragging = false
transformSidebar()
}
function transitionSidebar() {
sidebarDrag = lerp(sidebarDrag, sidebarOpen, 0.3)
if ((!sidebarOpen && sidebarDrag < 0.05) || (sidebarOpen && sidebarDrag > 0.95)) {
sidebarDrag = Math.round(sidebarDrag)
}
else {
requestAnimationFrame(transitionSidebar)
}
transformSidebar()
}
function transformSidebar() {
if (window.innerWidth < 1200) {
sidebarBackground.style.background = `rgba(0, 0, 0, ${0.2 * sidebarDrag})`
sidebar.style.transform = `translateX(${(sidebarDrag - 1) * 100}%)`
}
else {
sidebarBackground.style.background = `rgba(0, 0, 0, 0)`
sidebar.style.transform = `translateX(0%)`
}
}
transformSidebar()
// Embedded switches
if (window.parent !== window) {
document.documentElement.setAttribute("embedded", "true")
mainCanvasPost.onclick = function() {
sendParentMessage('switchGameServer')
}
}
else {
document.documentElement.setAttribute("embedded", "false")
postsManager.addEventListener("load", async () => {
tryLoadBottomPosts()
updateDialogTop(0)
// TODO: Until accounts are enabled
createPostPost.style.opacity = "0.6"
createPostPost.style.pointerEvents = "none"
createPostInput.disabled = true
createPostTitle.disabled = true
liveChatPost.remove()
overlayPost.remove()
mainCanvasPost.onclick = function() {
window.open(`${window.location.origin}/?server=${DEFAULT_SERVER}&board=${DEFAULT_BOARD}`)
}
// Load more posts on scroll down
const body = document.body
body.addEventListener("scroll", function(e) {
const bodyMaxScroll = body.scrollHeight - body.clientHeight
if (bodyMaxScroll - body.scrollTop < 256 && postsSearchbar.dataset.searching != "true") {
tryLoadBottomPosts()
}
}, { passive: true })
// Sidebar navigation
contents.addEventListener("touchstart", (e) => {
sidebarDragging = true
sidebarDragStartX = sidebarDragLastX = e.touches[0].clientX
sidebarDragStartY = e.touches[0].clientY
transformSidebar()
})
contents.addEventListener("touchmove", (e) => {
if (!sidebarDragging) {
return
}
const deltaY = sidebarDragStartY - e.touches[0].clientY
if (deltaY > 16 && sidebarDrag < 0.1) {
closeSidebar()
}
const deltaX = e.touches[0].clientX - sidebarDragLastX
sidebarDrag = Math.max(0, Math.min(sidebarDrag + (deltaX / sidebar.offsetWidth), 1))
transformSidebar()
sidebarDragLastX = e.touches[0].clientX
})
contents.addEventListener("touchend", (e) => {
sidebarOpen = sidebarDrag > 0.3
sidebarDragging = false
requestAnimationFrame(transitionSidebar)
})
contents.addEventListener("click", closeSidebar)
window.addEventListener("resize", transformSidebar)
})
}
async function uploadPost(title, content, contents, progressCb) {
const postData = {
canvasUser: null,
accountId: null,
title: title,
description: content
}
// TODO: Until global auth accounts are released, we will do all post authentications
// TODO: through the canvas account linkage API
// Get link key from canvas server to prove we own this account ID
const linkInfo = await makeParentRequest("fetchLinkKey")
if (!linkInfo) {
alert("Could not upload post. Error communicating with server")
console.error("Could not upload post, linkinfo was falsy", linkInfo)
return false
}
postData.canvasUser = linkInfo // { linkKey: number, instanceId: number }
if (progressCb) progressCb("uploadPost", { progress: 0 })
const uploadResponse = await fetch(`${localStorage.auth || DEFAULT_AUTH}/posts/upload`, {
method: "POST",
body: JSON.stringify(postData),
headers: { "Content-Type": "application/json" }
})
if (!uploadResponse.ok) {
if (uploadResponse.status == 401) {
alert("Error: You are being rate limited. Please wait before posting again")
}
else {
const jsonError = await uploadResponse.json().catch(e => console.error(e))
alert("Error: Could not upload post: " + jsonError.message)
console.error(uploadResponse.status, uploadResponse.statusText)
}
return false
}
if (progressCb) progressCb("uploadPost", { progress: 1 })
// Upload file as form content
let contentsUploaded = 0
let contentsUploadedSuccess = 0
const contentUploadTasks = []
const uploadResponseObject = await uploadResponse.json()
contents.forEach((file, index) => {
const contentForm = new FormData() // new Blob([], { type: "text/plain" })
contentForm.append("contentUploadKey", uploadResponseObject.contentUploadKey)
contentForm.append("file", file)
contentUploadTasks.push(
fetch(`${localStorage.auth || DEFAULT_AUTH}/posts/${uploadResponseObject.postId}/contents/`, {
method: "POST",
body: contentForm,
})
.then(async (contentResponse) => {
if (!contentResponse.ok) {
const jsonError = await contentResponse.json().catch(e => console.error(e))
alert("Error: Failed to upload one of the post attachments: " + jsonError.message)
console.error(contentResponse.status, contentResponse.statusText)
contentsUploadedSuccess++
}
contentsUploaded++
if (progressCb) progressCb("uploadContent", {
current: index,
success: contentResponse.ok,
uploaded: contentsUploaded,
successfullyUploaded: contentsUploadedSuccess,
total: contents.length
})
})
.catch(e => {
alert("Error: Failed to upload one of the post attachments")
console.error(e)
}))
})
await Promise.all(contentUploadTasks)
return true
}
function resetCreatePost() {
createPostButton.disabled = false
discardPostButton.disabled = false
createPostStatus.textContent = ""
createPostTitle.value = ""
createPostInput.value = ""
createPostContent.clearContents()
createPostInput.placeholder = "Create post..."
createPostPost.classList.remove("focused")
}
/*call(addEventListener, signupButton, 'click', function(e) {
signupUsername.style.border = 'initial'
signupEmail.style.border = 'initial'
if (signupUsername.value.length < 4) {
signupUsername.style.border = '1px solid red'
loginSignupMessage.textContent = 'Username is too short!'
return
}
if (!signupEmail.validity.valid) {
signupEmail.style.border = '1px solid red'
loginSignupMessage.textContent = 'Email is not valid!'
return
}
loginSignupMessage.textContent = ''
//authCodePage.style.display = 'flex'
//signupPage.style.display = 'none'
let buffer = encoder.encode('X' + signupUsername.value.padEnd(32) + signupEmail.value.padEnd(320))
buffer[0] = 2 // ClientPackets.CreateAccount
call(send, authSocket, buffer)
})
call(addEventListener, signinButton, 'click', function() {
let buffer = encoder.encode('X' + loginUsername.value.padEnd(32) + loginEmail.value.padEnd(320))
buffer[0] = 5 //ClientPackets.Authenticate
call(send, authSocket, buffer)
//authCodePage.style.display = 'flex'
//signinPage.style.display = 'none'
})
call(addEventListener, authCodeButton, 'click', function() {
let buffer = encoder.encode('X' + authCode.value)
buffer[0] = 3 // ClientPackets.AccountCode
call(send, authSocket, buffer)
//authCodePage.style.display = 'none'
//signinPage.style.display = 'flex'
})
call(addEventListener, profileDiscordSubmit, 'click', function() {
let view = new DataView(new Uint8Array(10).buffer)
view.setUint8(0, 11) // ClientPackets.UpdateProfile
view.setUint8(1, 1) // PublicEditableData.DiscordSnowflake
view.setBigInt64(2, BigInt(parseInt(profileDiscordInput.value)))
call(send, authSocket, view.buffer)
call(send, authSocket, new Uint8Array([4]))
})
call(addEventListener, profileTwitterSubmit, 'click', function() {
let buffer = encoder.encode('XX' + profileTwitterInput.value)
buffer[0] = 11 // ClientPackets.UpdateProfile
buffer[1] = 2 // PublicEditableData.TwitterHandle
call(send, authSocket, buffer)
call(send, authSocket, new Uint8Array([4]))
})
call(addEventListener, profileRedditSubmit, 'click', function() {
let buffer = encoder.encode('XX' + profileRedditInput.value)
buffer[0] = 11 // ClientPackets.UpdateProfile
buffer[1] = 3 // PublicEditableData.RedditHandle
call(send, authSocket, buffer)
call(send, authSocket, new Uint8Array([4]))
})
*/
translateAll()
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
sendParentMessage("resizePostsFrame")
}
})
resizeObserver.observe(contents)
</script>
</html>