-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
495 lines (487 loc) Β· 26.3 KB
/
index.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
<!DOCTYPE html>
<html lang="en" ontouchstart="if(!chatPanel.contains(event.target))event.preventDefault()" ontouchend="if(!chatPanel.contains(event.target))event.preventDefault()">
<head>
<link rel="manifest" href="manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="favicon.png">
<meta name="apple-mobile-web-app-title" content="place">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet">
<title>place</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<meta property="og:title" content="r/place 2" />
<meta property="og:description" content="I honestly nearly cried when r/place ended so here is a faithful recreation with the same map for you all to have fun on!" />
<meta property="og:image" content="https://preview.redd.it/rreqw9qpy8r81.png?auto=webp&s=f58d371c5505d66439c82de9040dfd99a3685015" />
<meta name="theme-color" content="#ff4500">
</head>
<body onkeypress="scanDocumentShortcuts(event)">
<div id="donate" noselect onclick="window.open('https://bit.ly/3LVwDtW','_blank')">Donate</div>
<div id="posel" noselect>(0,0) 2.5x</div>
<div id="place" noselect onclick="if(CD<Date.now())zoomIn(),showPalette();else audios.invalid.run()">Connecting...</div>
<div id="chat" noselect onclick="showChat()">Chat</div>
<div id="chatPanel" style="visibility: visible; transform: translateX(calc(100% + 50px));">
<div id="namePanel" style="position: absolute; top: 50%; transform: translateY(-50%); text-align: center; width: calc(100% - 20px); padding: 10px; background-color: white; border-radius: 15px;">
<h2>Enter a nickname to continue:</h2>
<h4 style="color: lightgrey;">Devam etmek için bir takma ad girin:</h4>
<br>
<input id="nameInput" type="text" placeholder="Enter nickname..." enterkeyhint="enter" onkeypress="if(event.keyCode==13)setName(this.value),this.value=''" maxlength="15">
</div>
<div style="display: flex; flex-direction: row;" noselect>
<h2 style="margin-bottom: 5px; flex: auto;">Live Chat:</h2>
<div style="height:30px; width: 60px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.4); display: flex; flex-direction: row; margin-right: 20px;">
<span style="flex: auto; line-height: 30px; text-align: center; border-radius: 5px 0px 0px 5px; background-color: transparent;">TK</span>
<span style="flex: auto; line-height: 30px; text-align: center; border-radius: 0px 5px 5px 0px; background-color: lightgray;">EN</span>
</div>
<div id="onlinepanel" noselect> <p id="onlineCounter">...</p> <svg id="playerIcon" stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 448 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" style="display: inline;"><path d="M224 256c70.7 0 128-57.3 128-128S294.7 0 224 0 96 57.3 96 128s57.3 128 128 128zm89.6 32h-16.7c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16h-16.7C60.2 288 0 348.2 0 422.4V464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48v-41.6c0-74.2-60.2-134.4-134.4-134.4z"></path></svg> </div>
<icon-close noselect="" id="close-btn" onclick="messageInput.blur(); hideChat()" class="active" style="flex: initial;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" class="active"><path d="M18.442 2.442l-.884-.884L10 9.116 2.442 1.558l-.884.884L9.116 10l-7.558 7.558.884.884L10 10.884l7.558 7.558.884-.884L10.884 10l7.558-7.558z" class=""></path></svg></icon-close>
</div>
<br>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7492601452630734" crossorigin="anonymous"></script>
<!-- Chat Ad -->
<div><ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-7492601452630734"
data-ad-slot="4496076769"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
</div>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});setInterval(()=>{chatPanel.style.height="calc(100% - 85px)";document.querySelector(".adsbygoogle").style.height="150px"},100)
</script>
<div id="chatMessages" style="overflow-wrap: break-word; word-wrap: break-word; font-family:mono;white-space: pre-wrap; max-height: calc(100% - 240px); overflow: auto; z-index: -1;"></div>
<input id="messageInput" type="text" placeholder="Enter message..." enterkeyhint="send" onkeypress="if(event.keyCode==13)sendMsg(this.value),this.value=''" maxlength="200">
</div>
<canvas id="canvas" width="0" height="0" noselect></canvas>
<div id="canvparent1" noselect>
<img id="edge" height="226" width="290" src="https://www.redditstatic.com/mona-lisa/assets/img/snoo-edge.png" />
</div>
<div id="canvparent2" noselect>
<div id="canvselect">
<svg fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" height="120%" width="120%" style="position: absolute;top: -10%;left: -10%;">
<g stroke-opacity=".6" stroke-width="2"> <g stroke="#000"> <path d="m3 9v-6h6"></path> <path d="m14.9999 3h6v6"></path> <path d="m20.9999 15.0001v6h-6"></path> <path d="m9 21.0001h-6v-6"></path> </g> <path d="m1 9v-8h8" stroke="#fff"></path> <path d="m15 1h8v8" stroke="#fff"></path> <path d="m23 15v8h-8" stroke="#fff"></path> <path d="m9 23h-8v-8" stroke="#fff"></path> </g>
</svg>
</div>
</div>
<div noselect id="helpbtn" onclick="if(modal.style.display=='flex'){modal.style.display='none';bg.style.display='none'}else{modal.style.display='flex';bg.style.display='block'}"><svg xmlns="http://www.w3.org/2000/svg" data-name="icons final" viewBox="0 0 20 20"><path d="M10 .875A9.125 9.125 0 1019.125 10 9.135 9.135 0 0010 .875zm0 17A7.875 7.875 0 1117.875 10 7.884 7.884 0 0110 17.875z"></path><path d="M10.479 13.635a1.085 1.085 0 00-.547-.141 1.035 1.035 0 00-.537.145 1.009 1.009 0 00-.379.388 1.1 1.1 0 00-.137.547 1.018 1.018 0 00.143.533 1.045 1.045 0 00.387.38 1.056 1.056 0 00.536.14 1.076 1.076 0 00.54-.14 1.008 1.008 0 00.387-.385 1.08 1.08 0 00.14-.541 1.05 1.05 0 00-.533-.926zM11.507 5.641a3.213 3.213 0 00-1.425-.309 3.15 3.15 0 00-1.535.368 2.646 2.646 0 00-1.028.974 2.52 2.52 0 00-.363 1.312h1.463a1.172 1.172 0 01.181-.661 1.327 1.327 0 01.516-.468 1.623 1.623 0 011.415-.017 1.212 1.212 0 01.5.431 1.1 1.1 0 01.181.618 1.063 1.063 0 01-.119.5 1.56 1.56 0 01-.3.4 9.531 9.531 0 01-.492.43 6.846 6.846 0 00-.656.585 2.292 2.292 0 00-.431.656 2.206 2.206 0 00-.178.919v.766h1.429v-.793a1.281 1.281 0 01.13-.58 1.824 1.824 0 01.321-.459c.128-.132.3-.3.533-.493a7.691 7.691 0 00.633-.584 2.279 2.279 0 00.41-.622 2.015 2.015 0 00.167-.85A2.262 2.262 0 0012.5 6.5a2.41 2.41 0 00-.993-.859z"></path></svg></div>
<div id="bg" style="display:none;position:fixed;top:0;left:0;bottom:0;right:0;background:rgba(0,0,0,.4);z-index:6"></div>
<div id="modal" style="display:none"><div id="modal-header"> <h2>Place</h2> <icon-close noselect id="close-btn" onclick="modal.style.display='none';bg.style.display='none'"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M18.442 2.442l-.884-.884L10 9.116 2.442 1.558l-.884.884L9.116 10l-7.558 7.558.884.884L10 10.884l7.558 7.558.884-.884L10.884 10l7.558-7.558z"></path></svg></icon-close> </div> <div id="modal-content">There is an empty canvas.<br><br>You may place a tile upon it, but you must wait to place another.<br><br>Individually you can create something.<br><br>Together you can create something more.</div> <div> <a href="https://discord.gg/dgEF6wvBzj" onclick="window.open('https:\/\/discord.gg/dgEF6wvBzj','_blank')">Join the Discord!</a><span onclick='localStorage.vip=prompt("Enter key?")'> </span><a href="https://www.patreon.com/rplace" onclick="window.open('https:\/\/www.patreon.com/rplace','_blank')">Donate</a> </div> <div id="modal-footer"> <mute-button noselect onclick="muted=!muted;mutesvg.innerHTML=muted?mutedhtml:unmutedhtml"><svg xmlns="http://www.w3.org/2000/svg" id="mutesvg" viewBox="0 0 20 20"></svg></mute-button><img noselect alt="Place Logo" height="40" width="40" src="https://www.redditstatic.com/mona-lisa/assets/img/place-logo.svg" /></div> </div>
<div id="palette" style="transform: translateY(100%)" noselect>
<div id="colors">
</div>
<div class="buttons">
<div class="pcancel" onclick="audios.closePalette.run();canvselect.style.background='';palette.style.transform='translateY(100%)';if(PEN!=-1){colors.children[PEN].classList.remove('sel');PEN=-1};pok.classList.remove('enabled');canvselect.children[0].style.display='block';canvselect.style.outline='';canvselect.style.boxShadow=''; hideIndicators()"><svg xmlns="http://www.w3.org/2000/svg" data-name="icons final" viewBox="0 0 20 20"><path d="M18.442 2.442l-.884-.884L10 9.116 2.442 1.558l-.884.884L9.116 10l-7.558 7.558.884.884L10 10.884l7.558 7.558.884-.884L10.884 10l7.558-7.558z"></path></svg></div>
<div id="pok" class="pok" onclick="put(); hideIndicators()"><svg xmlns="http://www.w3.org/2000/svg" data-name="icons final" viewBox="0 0 20 20"><path d="M7.5 15.583a.72.72 0 01-.513-.212L1.558 9.942l.884-.884L7.5 14.116 18.058 3.558l.884.884L8.013 15.371a.72.72 0 01-.513.212z"></path></svg></div>
</div>
</div>
</body>
<script>
const PALETTE = [0xff1a006d,0xff3900be,0xff0045ff,0xff00a8ff,0xff35d6ff,0xffb8f8ff,0xff68a300,0xff78cc00,0xff56ed7e,0xff6f7500,0xffaa9e00,0xffc0cc00,0xffa45024,0xffea9036,0xfff4e951,0xffc13a49,0xffff5c6a,0xffffb394,0xff9f1e81,0xffc04ab4,0xffffabe4,0xff7f10de,0xff8138ff,0xffaa99ff,0xff2f486d,0xff26699c,0xff70b4ff,0xff000000,0xff525251,0xff908d89,0xffd9d7d4,0xffffffff]
const WIDTH = 2000
const HEIGHT = 2000
let COOLDOWN = 10e3
</script>
<script>
let actives = new Map()
actives.set(-2, [])
let touch1 = null, touch2 = null, touchmoved = 3;
document.body.ontouchstart = function(e){
for(let t of e.changedTouches){
if(!touch1)touch1 = t, touchmoved = 3
else if(!touch2)touch2 = t
else [touch1, touch2] = [touch2, t]
let ac = []
let el = e.target
while(el){
el.classList.add("active")
ac.push(el)
el = el.parentElement
}
actives.set(t.identifier, ac)
}
}
document.body.ontouchend = function(e){
for(let t of e.changedTouches){
a: if(touch2 && touch2.identifier == t.identifier)touch2 = null
else if(touch1 && touch1.identifier == t.identifier){
[touch1, touch2] = [touch2, null]
if(touchmoved > 0 && canvparent2.contains(e.target)){
if(e.target != document.body && !canvparent2.contains(e.target))break a
clicked(t.clientX, t.clientY)
}
}
for(let el of actives.get(t.identifier))el.classList.remove("active")
actives.delete(t.identifier)
if('value' in e.target)e.target.focus()
else{let target = e.target; while(!target.click)target = target.parentElement;target.click()}
}
}
let moved = 3
document.body.onmousedown = function(e){
moved = 3
click = e.button + 1
}
document.body.onmouseup = function(e){
if(e.target != document.body && !canvparent2.contains(e.target))return (moved = 3, click = 0)
if(moved > 0 && canvparent2.contains(e.target)){
clicked(e.clientX, e.clientY)
}
moved = 3
click = 0
}
oncontextmenu = e => e.preventDefault()
let selX = 0, selY = 0
let c = canvas.getContext('2d')
function transform(){
canvparent1.style.transform = canvparent2.style.transform = "translate("+(x*z*-120+innerWidth/2)+"px, "+(y*z*-120+innerHeight/2)+"px) scale("+z*120+")"
canvselect.style.transform = "translate("+Math.floor(x)+"px, "+Math.floor(y)+"px) scale(0.01)"
canvas.style.width = z * canvas.width * 120 + "px"
canvas.style.height = z * canvas.height * 120 + "px"
canvas.style.transform = "translate("+x*z*-120+"px, "+y*z*-120+"px)"
}
let x, y, z, board, minZoom;
function setsize(w, h = w){
canvas.width = w
canvas.height = h
canvparent1.style.width = w + "px"
canvparent1.style.height = h + "px"
canvparent2.style.width = w + "px"
canvparent2.style.height = h + "px"
board = new Uint8Array(w * h).fill(31)
let i = board.length
x = +localStorage.x || WIDTH/2
y = +localStorage.y || HEIGHT/2
z = +localStorage.z || 0.2
for(let [k, v] of new URLSearchParams(location.search)){
v *= 1; if(v != v)continue
switch(k){
case 'x': x = v; break
case 'y': y = v; break
case 'z': z = v; break
case 'err': onerror = alert; break
case 'debug': break
}
}
onresize()
pos()
}
onresize = function(){
minZoom = Math.min(innerWidth / canvas.width, innerHeight / canvas.height) / 240
pos()
}
let click = false
let mx, my;
document.body.onmousemove = function(e){
if(e.target != document.body && !canvparent2.contains(e.target))return
moved--
let dx = -(mx - (mx = e.clientX - innerWidth / 2))
let dy = -(my - (my = e.clientY - innerHeight / 2))
if(dx != dx || dy != dy)return
if(click){
x -= dx / (z * 120)
y -= dy / (z * 120)
pos()
clearInterval(anim)
}
}
document.body.onwheel = function(e){
if(e.target != document.body && !canvparent2.contains(e.target))return
let d = Math.max(minZoom / z, Math.min(0.995 ** e.deltaY, 1 / z))
z *= d
x += mx * (d - 1) / z / 120
y += my * (d - 1) / z / 120
pos()
}
function pos(){
if(z < minZoom)z = minZoom
if(z > 1)z = 1
let right = x - canvas.width + 0.01
let left = x
let up = y - canvas.height + 0.01
let down = y
if(right >= left) x = 0
else if(right > 0) x -= right
else if(left < 0) x -= left
if(up >= down) y = 0
else if(up > 0) y -= up
else if(down < 0) y -= down
posel.textContent = `(${Math.floor(x)},${Math.floor(y)}) ${z > 0.02 ? Math.round(z*50)/10 : Math.round(z*500)/100}x`
localStorage.x = Math.floor(x) + 0.5
localStorage.y = Math.floor(y) + 0.5
localStorage.z = z
transform()
}
function renderAll(){
let img = new ImageData(canvas.width, canvas.height)
let data = new Uint32Array(img.data.buffer)
let len = board.length
for(let i = 0; i < len; i++){
data[i] = PALETTE[board[i]]
}
c.putImageData(img, 0, 0)
}
let xa = new Uint32Array(1)
let xb = new Uint8Array(xa.buffer)
function set(x, y, b){
board[x % canvas.width + (y % canvas.height) * canvas.width] = b
xa[0] = PALETTE[b]
c.fillStyle = "#" + (xb[0] < 16 ? "0" : "") + xb[0].toString(16) + (xb[1] < 16 ? "0" : "") + xb[1].toString(16) + (xb[2] < 16 ? "0" : "") + xb[2].toString(16) + (xb[3] < 16 ? "0" : "") + xb[3].toString(16)
c.clearRect(x,y,1,1)
c.fillRect(x,y,1,1)
}
document.body.ontouchmove = e => {touchmoved--;for(let t of e.changedTouches){
clearInterval(anim)
a: if(!touch2 && touch1 && touch1.identifier == t.identifier){
if(e.target != document.body && !canvparent2.contains(e.target))break a
x -= (t.clientX - touch1.clientX) / (z * 120)
y -= (t.clientY - touch1.clientY) / (z * 120)
pos()
}else if(touch1 && touch2){
if(e.target != document.body && !canvparent2.contains(e.target))break a
let touch = touch1.identifier == t.identifier ? touch1 : (touch2.identifier == t.identifier ? touch2 : null)
if(!touch)break a
let other = touch == touch1 ? touch2 : touch1
x -= (t.clientX - touch.clientX) / (z * 120)
y -= (t.clientY - touch.clientY) / (z * 120)
let dx = touch.clientX - other.clientX
let dy = touch.clientY - other.clientY
let a = dx * dx + dy * dy
dx = t.clientX - other.clientX
dy = t.clientY - other.clientY
a = Math.sqrt((dx * dx + dy * dy) / a)
z *= a
pos()
}
if(touch1 && touch1.identifier == t.identifier)touch1 = t
else if(touch2 && touch2.identifier == t.identifier)touch2 = t
}}
setsize(WIDTH, HEIGHT)
renderAll()
let anim = null
function clicked(clientX, clientY){
clearInterval(anim)
clientX = Math.floor(x+(clientX-innerWidth/2)/z/120) + 0.5
clientY = Math.floor(y+(clientY-innerHeight/2)/z/120) + 0.5
if(clientX == Math.floor(x) + 0.5 && clientY == Math.floor(y) + 0.5){
clientX -= 0.5; clientY -= 0.5
if(CD<Date.now())zoomIn(),showPalette()
else audios.invalid.run()
return
}
(CD > Date.now() ? audios.invalid : audios.highlight).run()
anim = setInterval(function(){
x += (clientX - x) / 10
y += (clientY - y) / 10
pos()
if(Math.abs(clientX - x) + Math.abs(clientY - y) < 0.1)clearInterval(anim)
},15)
}
function zoomIn(){
if(z >= 0.4)return
clearInterval(anim)
let dz = 0.005
anim = setInterval(function(){
if(dz < 0.2)dz *= 1.1
z *= 1 + dz
pos()
if(z >= 0.4)clearInterval(anim)
}, 15)
}
let audios = {
invalid: new Audio('https://hot-potato.reddit.com/media/interactions/invalid.mp3'),
highlight: new Audio('https://hot-potato.reddit.com/media/interactions/highlight.mp3'),
selectColor: new Audio('https://hot-potato.reddit.com/media/interactions/select-color.mp3'),
closePalette: new Audio('https://hot-potato.reddit.com/media/interactions/close-pallette.mp3'),
cooldownStart: new Audio('https://hot-potato.reddit.com/media/interactions/cooldown-start.mp3'),
cooldownEnd: new Audio('https://hot-potato.reddit.com/media/interactions/cooldown-end.mp3')
}
Audio.prototype.run = function(){
if(muted)return
this.currentTime = 0
setTimeout(this.play.bind(this))
}
let muted = false, unmutedhtml = '<path d="M10.543.5a1.12 1.12 0 00-1.182.117L3.789 4.875h-1.8A1.127 1.127 0 00.868 6v8a1.127 1.127 0 001.125 1.125h1.8l5.572 4.258a1.117 1.117 0 00.681.232 1.128 1.128 0 001.127-1.126V1.511A1.119 1.119 0 0010.543.5zm-.624 17.736l-5.708-4.361H2.118v-7.75h2.093l5.708-4.361zM13 3.375v1.25a5.375 5.375 0 010 10.75v1.25a6.625 6.625 0 000-13.25z"></path><path d="M16.125 10A3.129 3.129 0 0013 6.875v1.25a1.875 1.875 0 010 3.75v1.25A3.129 3.129 0 0016.125 10z"></path>', mutedhtml = '<path d="M19.442 7.442l-.884-.884L16.5 8.616l-2.058-2.058-.884.884L15.616 9.5l-2.058 2.058.884.884 2.058-2.058 2.058 2.058.884-.884L17.384 9.5l2.058-2.058zM10.543.5a1.12 1.12 0 00-1.182.117L3.789 4.875h-1.8A1.127 1.127 0 00.868 6v8a1.127 1.127 0 001.125 1.125h1.8l5.572 4.258a1.117 1.117 0 00.681.232 1.128 1.128 0 001.127-1.126V1.511A1.119 1.119 0 0010.543.5zm-.624 17.736l-5.708-4.361H2.118v-7.75h2.093l5.708-4.361z"></path>'
mutesvg.innerHTML = unmutedhtml
let CD = Infinity
let onCooldown = false
setInterval(() => {
let left = Math.floor((CD - Date.now()) / 1000)
place.innerHTML = load.buffer ? "Downloading image..." : (CD >= 1e100 ? (CD == Infinity ? 'Connecting...' : '<span style="color:#f50">Could not connect!</span>') : left > 0 ? `<svg xmlns="http://www.w3.org/2000/svg" data-name="icons final" viewBox="0 0 20 20" style="height: 1.1rem;vertical-align:top"><path d="M13.558 14.442l-4.183-4.183V4h1.25v5.741l3.817 3.817-.884.884z"></path><path d="M10 19.625A9.625 9.625 0 1119.625 10 9.636 9.636 0 0110 19.625zm0-18A8.375 8.375 0 1018.375 10 8.384 8.384 0 0010 1.625z"></path></svg> ${(''+Math.floor(left/3600)).padStart(2,"0")}:${(''+Math.floor((left/60))%60).padStart(2,"0")}:${(''+left%60).padStart(2,"0")}` : "Place a tile")
if(CD > Date.now() && !onCooldown && !load.buffer)onCooldown = true
if(CD < Date.now() && onCooldown && !load.buffer){
onCooldown = false
if (!document.hasFocus()) audios.cooldownEnd.run()
}
}, 300)
function showPalette(){
palette.style.transform = ""
audios.highlight.play()
}
let PEN = -1
colors.innerHTML = PALETTE.map((a,i)=>`<div style='background:rgba(${a&255},${(a>>8)&255},${(a>>16)&255},1)${a==0xffffffff?";outline:1px #ddd solid;outline-offset:-1px":""}'><span style="background-color: rgba(255, 255, 255, 0.2); border-radius: 20px; width: 15px; height: 15px; position: absolute; text-align: center; line-height: 1; visibility: hidden;"></span></div>`).join('')
colors.onclick = function(e){
let i = [...this.children].indexOf(e.target)
if(i<0)return
let el = this.children[PEN]
if(el){
el.classList.remove('sel')
}
PEN = i
audios.selectColor.run()
canvselect.style.background = e.target.style.background
e.target.classList.add('sel')
pok.classList.add('enabled')
canvselect.children[0].style.display='none';canvselect.style.outline='8px white solid';canvselect.style.boxShadow='0px 2px 4px 0px rgb(0 0 0 / 50%)'
hideIndicators();
}
function put(){
if(CD>Date.now())return
canvselect.style.background='';palette.style.transform='translateY(100%)';colors.children[PEN].classList.remove('sel');pok.classList.remove('enabled')
set(Math.floor(x), Math.floor(y), PEN)
canvselect.children[0].style.display='block';canvselect.style.outline='';canvselect.style.boxShadow=''
audios.cooldownStart.run()
CD = Date.now() + (localStorage.vip ? (localStorage.vip[0] == '!' ? 0 : COOLDOWN/2) : COOLDOWN)
let a = new DataView(new Uint8Array(6).buffer)
a.setUint8(0, 4)
a.setUint32(1, Math.floor(x) + Math.floor(y) * WIDTH)
a.setUint8(5, PEN)
PEN=-1
ws.send(a)
}
function runLengthChanges(data){
let i = 1, boardI = 0
while(i < data.byteLength){
let cell = data.getUint8(i++)
let c = cell >> 6
if(c == 1)c = data.getUint8(i++)
else if(c == 2)c = data.getUint16(i++),i++
else if(c == 3)c = data.getUint32(i++),i+=3
boardI += c
seti(boardI++, cell & 63)
}
}
let load = false
fetch('place').then(a=>a.arrayBuffer()).then(a => {
board = new Uint8Array(a)
renderAll()
if(load)runLengthChanges(load)
load = true
})
const CHAT_COLOURS = ["lightblue", "navy", "green", "purple", "grey", "brown", "orangered", "gold"]
let online = 1
let hash = a => a.split("").reduce((a,b)=>(a*31+b.charCodeAt())>>>0,0)
let allowed = new Set("rplace.tk google.com wikipedia.org pxls.space".split(" ")), censor = a => a.replace(/fuc?k|shi[t]|c[u]nt/gi,a=>"*".repeat(a.length)).replace(/https?:\/\/(\w+\.)+\w{2,15}(\/\S*)?|(\w+\.)+\w{2,15}\/\S*|(\w+\.)+(tk|ga|gg|gq|cf|ml|fun|xxx|webcam|sexy?|tube|cam|p[o]rn|adult|com|net|org|online|ru|co|info|link)/gi, a => allowed.has(a.replace(/^https?:\/\//,"").split("/")[0]) ? a : "").trim()
let ws = new WebSocket('wss://rplaceserver.t3knical.com' + (localStorage.vip ? "/" + localStorage.vip : ""))
ws.onmessage = async function({data}){
data = new DataView(await data.arrayBuffer())
let code = data.getUint8(0)
if(code == 1){
CD = data.getUint32(1) * 1000
}else if(code == 2){
//run length coding
if(!load)load = data
else runLengthChanges(data)
}else if(code == 7){
CD = data.getUint32(1) * 1000
seti(data.getUint32(5), data.getUint8(9))
}else if(code == 6){
let i = 0
while(i < data.byteLength - 2){
seti(data.getUint32(i += 1), data.getUint8(i += 4))
}
}else if(code == 3){
online = data.getUint16(1)
document.getElementById("onlineCounter").textContent = online;
}else if(code == 15){
let txt = censor(decoder.decode(new Uint8Array(data.buffer).slice(1))).replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");
let name; [txt, name] = txt.split("\n")
if(name)name = name.replace(/\W+/g,'').toLowerCase()
if(!txt)return
if(txt.includes("πππππππ.ππ"))return
if(txt.includes("ππ’π¬ππ¨π«π.π π "))return
if(txt.includes("discord.gg"))return
if(name == "nors")return
if(name == "anlcan")return
let newMessage = document.createElement("div")
newMessage.innerHTML = `<span style="color: ${CHAT_COLOURS[name ? hash(name) & 7 : (Math.round(Math.random() * 8))]};">[${name || "anon"}]</span> ${txt}\n`
let scroll = chatMessages.scrollTop+chatMessages.offsetHeight+10>=chatMessages.scrollHeight
chatMessages.insertAdjacentElement("beforeEnd", newMessage)
if(chatMessages.children.length>100){
chatMessages.children[0].remove()
}
scroll && chatMessages.scrollTo(0,999999999)
}
}
ws.onclose = () => {
if(CD != Infinity)return location.reload()
//Something went wrong...
CD = 1e100
}
function seti(i, b){
board[i] = b
xa[0] = PALETTE[b]
c.fillStyle = "#" + (xb[0] < 16 ? "0" : "") + xb[0].toString(16) + (xb[1] < 16 ? "0" : "") + xb[1].toString(16) + (xb[2] < 16 ? "0" : "") + xb[2].toString(16) + (xb[3] < 16 ? "0" : "") + xb[3].toString(16)
c.fillRect(i % WIDTH, Math.floor(i / WIDTH), 1, 1)
}
function scanDocumentShortcuts(e) {
if (onCooldown) return
let keyIndex = null;
if(document.activeElement != document.body)return
if (e.keyCode >= 49 && e.keyCode <= 57) keyIndex = e.keyCode - 49
if (e.keyCode >= 97 && e.keyCode <= 119) keyIndex = e.keyCode - 97 + 9
if (keyIndex == null) return
if (palette.style.transform=='translateY(100%)')
showPalette()
for (let c = 0; c < document.getElementById("colors").children.length; c++) {
document.getElementById("colors").children[c].firstChild.style.visibility = "visible"
}
let i = [...(document.getElementById("colors").children)].indexOf(document.getElementById("colors").children[keyIndex])
if(i<0) return
let el = document.getElementById("colors").children[PEN]
if(el) {
el.classList.remove('sel')
}
PEN = keyIndex;
audios.selectColor.run()
canvselect.style.background = document.getElementById("colors").children[keyIndex].style.background
document.getElementById("colors").children[keyIndex].classList.add('sel')
pok.classList.add('enabled')
canvselect.children[0].style.display='none';canvselect.style.outline='8px white solid';canvselect.style.boxShadow='0px 2px 4px 0px rgb(0 0 0 / 50%)'
}
function hideIndicators() {
for (let c = 0; c < document.getElementById("colors").children.length; c++) {
document.getElementById("colors").children[c].firstChild.style.visibility = "hidden"
}
}
for (let c = 0; c < document.getElementById("colors").children.length; c++) {
let keybinds = "123456789abcdefghijklmnopqrstuvwxyz"
let indicator = document.getElementById("colors").children[c].firstChild
indicator.textContent = keybinds.charAt(c)
}
if (window.innerHeight > window.innerWidth) {
chatPanel.style.transform = "translateX(calc(100% + 50px))"
}
function showChat() {
chatPanel.style.transform = ""
}
function hideChat() {
if (window.innerHeight > window.innerWidth)
chatPanel.style.transform = "translateX(calc(100% + 50px))"
else
chatPanel.style.transform = "translateX(calc(100% + 50px))"
}
let encoder = new TextEncoder(), decoder = new TextDecoder()
function sendMsg(message){
ws.send(encoder.encode("\x0f" + message + (localStorage.name ? "\n" + localStorage.name : "")))
}
if (localStorage.getItem("name")) {
namePanel.style.visibility = "hidden"
}
function setName(name) {
localStorage.setItem("name", name);
namePanel.style.visibility = "hidden"
}
</script>
<!--script src="board_final.js"></script-->
</html>