-
Notifications
You must be signed in to change notification settings - Fork 19
/
script.js
6319 lines (5647 loc) · 277 KB
/
script.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
// yes its a mess
// no i wont do anything about it
// - Eris
// To-Do
// Modal close animation
// Discord mode where posts are on the bottom
// Notification managment
// Custom video and audio player, similar style as the file download preview
// make @Tnix have tnix colour ect
// Plugins options and API
// Online indicators
let end = false;
let page = "load";
const sidediv = document.querySelectorAll(".side");
sidediv.forEach(function(sidediv) {
sidediv.classList.add("hidden");
});
let lul = 0;
let eul;
let sul = "";
let pre;
if (settingsstuff().homepage) {
pre = "home"
} else {
pre = "start"
}
let loadpre = 0;
let meourl = 'https://eris.pages.dev/meo';
let bridges = ['Discord', 'SplashBridge', 'gc'];
let ipBlocked = false;
let openprofile = false;
const communityDiscordLink = "https://discord.com/invite/THgK9CgyYJ";
const server = "wss://server.meower.org/?v=1";
const pfpCache = {};
const postCache = { livechat: [] }; // {chatId: [post, post, ...]} (up to 25 posts for inactive chats)
const chatCache = {}; // {chatId: chat}
const blockedUsers = {}; // {user, user}
const usersTyping = {}; // {chatId: {username1: timeoutId, username2: timeoutId}}
let recentuser = "";
const recentCache = {};
let favoritedChats = []; // [chatId, ...]
let pendingAttachments = [];
let blockedWords;
if (localStorage.getItem("blockedWords")) {
blockedWords = JSON.parse(localStorage.getItem("blockedWords"));
} else {
blockedWords = {};
}
let lastTyped = 0;
let today = new Date();
let birthday = (today.getMonth() === 8 && today.getDate() >= 10 && today.getDate() <= 30);
if (birthday === 1) {
const script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/party-js@latest/bundle/party.min.js";
document.head.appendChild(script);
}
setAccessibilitySettings()
loadSavedPlugins();
loadCustomCss();
loadCustomTheme();
function replsh(rpl) {
const trimmedString = rpl.length > 25 ?
rpl.substring(0, 22) + "..." :
rpl;
return trimmedString;
}
if (settingsstuff().widemode) {
document.querySelectorAll('.side').forEach(element => {
element.remove();
});
const stylesheet = document.createElement('link');
stylesheet.rel = 'stylesheet';
stylesheet.href = 'mui.css';
document.head.appendChild(stylesheet);
const page = document.getElementById('page');
if (page) {
const ex = document.createElement('div');
ex.classList.add('sidebar');
ex.classList.add('hidden');
ex.innerHTML = `
<div id="nav" class="side"></div>
<div id="groups" class="side"></div>
`;
page.insertBefore(ex, page.firstChild);
}
} else if (settingsstuff().compactmode) {
const stylesheet = document.createElement('link');
stylesheet.rel = 'stylesheet';
stylesheet.href = 'compact.css';
document.head.appendChild(stylesheet);
}
if (settingsstuff().magnify) {
magnify();
}
if (settingsstuff().discord) {
document.querySelector('body').classList.add("discord");
}
let version;
checkver()
async function checkver() {
try {
const response = await fetch('https://api.github.com/repos/3r1s-s/meo/commits/main');
const data = await response.json();
version = data.sha;
console.log(version.substring(0, 7));
} catch (error) {
console.log('Error checking for updates:', error);
}
}
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('openprofile')) {
const username = urlParams.get('openprofile');
openUsrModal(username);
urlParams.delete('openprofile');
const newUrl = window.location.pathname + '?' + urlParams.toString();
if (urlParams.toString() === '') {
window.history.replaceState({}, document.title, window.location.pathname);
} else {
window.history.replaceState({}, document.title, newUrl);
}
} else if (urlParams.has('gc')){
const id = urlParams.get('gc');
sidebars();
loadchat(id);
urlParams.delete('gc');
const newUrl = window.location.pathname + '?' + urlParams.toString();
if (urlParams.toString() === '') {
window.history.replaceState({}, document.title, window.location.pathname);
} else {
window.history.replaceState({}, document.title, newUrl);
}
}
// make it so when reconnect happens it goes back to the prev screen and not the start page
function main() {
meowerConnection = new WebSocket(server);
meowerConnection.addEventListener('error', function(event) {
openUpdate('Connection error, please try again later!');
});
meowerConnection.onclose = (event) => {
logout(true);
};
page = "login";
loadtheme();
if ('windowControlsOverlay' in navigator) {
}
if (settingsstuff().notifications) {
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
}
meowerConnection.onopen = () => {
if (document.querySelector('#loading')) {
document.querySelector('#loading').style.setProperty('--load', `100%`);
} else {
console.log("Reconnecting...");
}
if (birthday === 1) {
party.confetti(document.body, {
count: party.variation.range(20, 40)
});
}
if (localStorage.getItem("token") != undefined && localStorage.getItem("username") != undefined) {
meowerConnection.send(JSON.stringify({
cmd: "authpswd",
val: {
username: localStorage.getItem("username"),
pswd: localStorage.getItem("token"),
},
listener: "auth",
}));
} else {
loadLogin();
};
};
meowerConnection.onmessage = (event) => {
console.log("INC: " + event.data);
const sentdata = JSON.parse(event.data);
if (sentdata.listener === "auth") {
if (sentdata.cmd === "auth") {
sentdata.val.relationships.forEach((relationship) => {
if (relationship.state === 2) {
blockedUsers[relationship.username] = true;
}
});
sentdata.val.chats.forEach((chat) => {
chatCache[chat._id] = chat;
});
localStorage.setItem("username", sentdata.val.username);
localStorage.setItem("token", sentdata.val.token);
localStorage.setItem("permissions", sentdata.val.account.permissions);
favoritedChats = sentdata.val.account.favorited_chats;
loadPfp(sentdata.val.username, sentdata.val.account);
sidebars();
renderChats();
// work on this
if (pre !== "") {
if (pre === "home") {
loadchat('home');
} else if (pre === "explore") {
loadexplore();
} else if (pre === "start") {
loadstart();
} else if (pre === "settings") {
loadstgs();
} else {
loadchat(pre);
}
} else {
loadstart();
}
if (openprofile) {
openUsrModal(localStorage.getItem("username"));
}
console.log("Logged in!");
} else if (sentdata.cmd == "statuscode" && sentdata.val != "I:100 | OK") {
if (sentdata.val === "E:018 | Account Banned")
openUpdate(lang().info.accbanned);
console.error(`Failed logging in to Cloudlink: ${sentdata.val}`);
logout(false);
}
} else if (sentdata.cmd === "post" || sentdata.cmd === "inbox_message") {
let post = sentdata.val;
let postOrigin = post.post_origin;
let postAuthor = post.author._id
if (usersTyping[postOrigin] && post.author._id in usersTyping[postOrigin]) {
clearTimeout(usersTyping[postOrigin][post.author._id]);
delete usersTyping[postOrigin][post.author._id];
renderTyping();
}
if (!(postOrigin in postCache)) postCache[postOrigin] = [];
postCache[postOrigin].unshift(post);
if (page === postOrigin) {
loadpost(Object.assign(structuredClone(post), { _top: true }));
} else {
if (postCache[postOrigin].length > 25) postCache[postOrigin].length = 25;
}
if (!(postAuthor in recentCache)) recentCache[postAuthor] = [];
recentCache[postAuthor].unshift(post);
if (page === "recent" && recentuser === postAuthor) {
loadpost(Object.assign(structuredClone(post), { _top: true }));
} else {
if (recentCache[postAuthor].length > 25) recentCache[postAuthor].length = 25;
}
if (settingsstuff().notifications) {
if (page !== postOrigin || document.hidden) {
notify(postOrigin === "inbox" ? "Inbox Message" : post.u, post.p, postOrigin, post);
}
}
} else if (sentdata.cmd === "typing") {
const chatId = sentdata.val.chat_id;
const username = sentdata.val.username;
if (username === localStorage.getItem("username")) return;
if (!(chatId in usersTyping)) usersTyping[chatId] = {};
if (username in usersTyping[chatId]) {
clearTimeout(usersTyping[chatId][username]);
}
usersTyping[chatId][username] = setTimeout(() => {
if (username in usersTyping[chatId]) {
clearTimeout(usersTyping[chatId][username]);
delete usersTyping[chatId][username];
renderTyping();
}
}, 4000);
renderTyping();
} else if (end) {
return 0;
} else if (sentdata.cmd == "update_config") {
if (sentdata.val.favorited_chats) {
favoritedChats = sentdata.val.favorited_chats;
renderChats();
}
} else if (sentdata.cmd == "update_profile") {
let username = sentdata.val._id;
if (pfpCache[username]) {
delete pfpCache[username];
loadPfp(username, null, 0)
.then(pfpElement => {
if (pfpElement) {
pfpCache[username] = pfpElement.cloneNode(true);
for (const elem of document.getElementsByClassName("avatar")) {
if (elem.getAttribute("data-username") !== username) continue;
elem.replaceWith(pfpElement.cloneNode(true));
}
}
});
}
} else if (sentdata.cmd == "update_post") {
let postOrigin = sentdata.val.post_origin;
let postAuthor = sentdata.val.author._id
if (postCache[postOrigin]) {
index = postCache[postOrigin].findIndex(post => post._id === sentdata.val._id);
if (index !== -1) {
postCache[postOrigin][index] = Object.assign(
postCache[postOrigin][index],
sentdata.val
);
}
}
if (recentCache[postAuthor]) {
index = recentCache[postAuthor].findIndex(post => post._id === sentdata.val._id);
if (index !== -1) {
recentCache[postAuthor][index] = Object.assign(
recentCache[postAuthor][index],
sentdata.val
);
}
}
if (document.getElementById(sentdata.val.post_id)) {
loadpost(sentdata.val);
}
} else if (sentdata.cmd === "delete_post") {
if (sentdata.val.chat_id in postCache) {
const index = postCache[sentdata.val.chat_id].findIndex(post => post._id === sentdata.val.post_id);
if (index !== -1) {
postCache[sentdata.val.chat_id].splice(index, 1);
}
}
for (const recentId in recentCache) {
const index = recentCache[recentId].findIndex(post => post._id === sentdata.val.post_id);
if (index !== -1) {
recentCache[recentId].splice(index, 1);
break;
}
}
/* the delete post command doesnt give author which is a problem :p
if (sentdata.val.author._id in recentCache) {
const index = recentCache[sentdata.val.author._id].findIndex(post => post._id === sentdata.val.post_id);
if (index !== -1) {
recentCache[sentdata.val.author._id].splice(index, 1);
}
}*/
const divToDelete = document.getElementById(sentdata.val.post_id);
if (divToDelete) {
divToDelete.parentNode.removeChild(divToDelete);
}
const replies = document.querySelectorAll(`#reply-${sentdata.val.post_id}`);
for (const reply of replies) {
reply.replaceWith(loadreplyv(null));
}
} else if (sentdata.cmd == "create_chat") {
chatCache[sentdata.val._id] = sentdata.val;
renderChats();
} else if (sentdata.cmd == "update_chat") {
const chatId = sentdata.val._id;
if (chatId in chatCache) {
chatCache[chatId] = Object.assign(
chatCache[chatId],
sentdata.val
);
renderChats();
}
} else if (sentdata.cmd === "delete_chat") {
if (chatCache[sentdata.val.chat_id]) {
delete chatCache[sentdata.val.chat_id];
}
if (postCache[sentdata.val.chat_id]) {
delete postCache[sentdata.val.chat_id];
renderChats();
}
if (page === sentdata.val.chat_id) {
openUpdate(lang().info.chatremoved);
if (!settingsstuff().homepage) {
loadstart();
} else {
loadchat('home');
}
}
} else if (sentdata.cmd == "create_emoji") {
const chatId = sentdata.val.chat_id;
if (chatId in chatCache) {
chatCache[chatId].emojis.push(sentdata.val);
}
} else if (sentdata.cmd == "update_emoji") {
const chatId = sentdata.val.chat_id;
if (chatId in chatCache) {
const emojiI = chatCache[chatId].emojis.findIndex(emoji => emoji._id === sentdata.val._id);
if (emojiI && emojiI !== -1) {
chatCache[chatId].emojis[emojiI] = Object.assign(
chatCache[chatId].emojis[emojiI],
sentdata.val,
);
}
}
} else if (sentdata.cmd == "delete_emoji") {
const chatId = sentdata.val.chat_id;
if (chatId in chatCache) {
chatCache[chatId].emojis = chatCache[chatId].emojis.filter(emoji => emoji._id !== sentdata.val._id);
}
} else if (sentdata.cmd == "ulist") {
const iul = sentdata.val;
sul = iul.trim().split(";");
eul = sul;
ful = sul.map((i) => `<span class="ulistentry" onclick="openUsrModal('${i}')">${i}</span>`)
lul = sul.length - 1;
if (ful.length > 1) {
ful = ful.slice(0, -2).join(", ") + (ful.length > 2 ? ", " : "") + ful.slice(-2).join(".");
} else {
ful = ful[0];
}
if (page == "home") {
if (settingsstuff().ulist) {
document.getElementById("info-ulist").innerHTML = `${lul} ${lang().meo_userson} (${ful})`;
} else {
document.getElementById("info-ulist").innerText = `${lul} ${lang().meo_userson}`;
}
}
}
};
document.addEventListener("keydown", function(event) {
if (page !== "settings" && page !== "explore" && page !== "login" && page !== "start") {
const textarea = document.getElementById("msg");
const emj = document.getElementById("emojin");
if (event.key === "Enter" && !event.shiftKey) {
if (settingsstuff().entersend) {
if (textarea === document.activeElement) {
} else if (emj === document.activeElement) {
if (opened === 1) {
fstemj();
}
}
} else {
if (textarea === document.activeElement) {
event.preventDefault();
sendpost();
textarea.style.height = 'auto';
} else {
if (emj === document.activeElement) {
if (opened === 1) {
fstemj();
}
}
}
}
} else if (event.key === "Escape") {
closemodal();
closeImage();
if (opened===1) {
closepicker();
}
const editIndicator = document.getElementById("edit-indicator");
if (editIndicator.hasAttribute("data-postid")) {
cancelEdit();
}
const replies = document.getElementById("replies");
if (replies) {
replies.innerHTML = "";
}
textarea.blur();
} else if (event.keyCode >= 48 && event.keyCode <= 90 && textarea === document.activeElement && !settingsstuff().invtyping && lastTyped+3000 < Date.now()) {
lastTyped = Date.now();
fetch(`https://api.meower.org/${page === "home" ? "" : "chats/"}${page}/typing`, {
method: "POST",
headers: { token: localStorage.getItem("token") }
});
}
}
});
addEventListener("DOMContentLoaded", () => {
document.onpaste = (event) => {
if (!document.getElementById("msg") || page === "livechat") return;
for (const file of event.clipboardData.files) {
addAttachment(file);
}
};
const mainEl = document.getElementById("main");
mainEl.addEventListener("scroll", async (event) => {
if (!(page in postCache || page == "recent" )) return;
const skeletonHeight = document.getElementById("skeleton-msgs").scrollHeight;
if (mainEl.scrollHeight - mainEl.scrollTop - skeletonHeight - mainEl.clientHeight < 1) {
const msgs = document.getElementById("msgs");
if (msgs.hasAttribute("data-loading-more")) return;
msgs.setAttribute("data-loading-more", "");
if (page != "recent") {
await loadposts(Math.floor(msgs.childElementCount / 25) + 1);
} else {
await loadrecentposts(Math.floor(msgs.childElementCount / 25) + 1);
}
msgs.removeAttribute("data-loading-more");
}
});
});
addEventListener("keydown", (event) => {
if (!event.ctrlKey && event.keyCode >= 48 && event.keyCode <= 90) {
if (!document.activeElement || (document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA')) {
if (page !== "settings" && page !== "explore" && page !== "login" && page !== "start") {
document.getElementById("msg").focus();
}
}
} else if ((event.ctrlKey || event.metaKey) && event.key === 's') {
if (page !== "settings" && page !== "explore" && page !== "login" && page !== "start") {
event.preventDefault();
togglePicker();
}
} else if ((event.ctrlKey || event.metaKey) && event.key === 'e') {
if (postCache[page]) {
event.preventDefault();
const post = [...postCache[page]].find(post => post.u === localStorage.getItem("username"));
if (post) {
editPost(page, post._id);
}
}
} else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
if (!document.activeElement || (document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA')) {
if (page !== "settings" && page !== "explore" && page !== "login" && page !== "start") {
document.getElementById("msg").focus();
}
}
} else if ((event.ctrlKey || event.metaKey) && event.key === 'u') {
if (page !== "settings" && page !== "explore" && page !== "login" && page !== "start") {
event.preventDefault();
const editIndicator = document.getElementById("edit-indicator");
if (!editIndicator.hasAttribute("data-postid")) {
selectFiles();
}
}
} else if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
event.preventDefault();
goAnywhere();
} else if ((event.ctrlKey || event.metaKey) && event.key === '/') {
event.preventDefault();
document.getElementById("msg").focus();
} else if ((event.ctrlKey || event.metaKey) && event.key === '.') {
event.preventDefault();
shortcutsModal();
}
});
}
function loadLogin() {
const pageContainer = document.getElementById("main");
pageContainer.innerHTML =
`<div class='login'>
<div class='login-inner'>
<h2 id="login-header" class="login-header">${lang().meo_welcome}</h2>
<input type="text" id="userinput" placeholder="${lang().meo_username}" class="login-text text" aria-label="username input" autocomplete="username">
<input type="password" id="passinput" placeholder="${lang().meo_password}" class="login-text text" aria-label="password input" autocomplete="current-password">
<input type="text" id="otpinput" placeholder="${lang().meo_totp}" class="login-text text" aria-label="one-time-code input" autocomplete="one-time-code" style="display:none;">
<input type="button" id="login" value="${lang().action.login}" class="login-button button" onclick="toggleLogin(true);login()" aria-label="Register">
<input type="button" id="signup" value="${lang().action.signup}" class="login-button button" onclick="agreementModal()" aria-label="log in" style="display:none;">
<input type="button" id="back" value="${lang().action.back}" class="login-button button" onclick="loadLogin()" aria-label="back" style="display:none;">
<div class="login-sub">
<a onclick="toggleSignUp(false)" id="togglesignup">${lang().action.signup}</a>
<small>${lang().login_sub.desc}</small>
</div>
</div>
<div class="login-top">
<svg width="80" height="44.25" viewBox="0 0 321 200" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M124.695 17.2859L175.713 0.216682C184.63 -1.38586 192.437 6.14467 190.775 14.7463L177.15 68.2185C184.648 86.0893 187.163 104.122 187.163 115.032C187.163 143.057 174.929 178 95.4997 178C16.0716 178 3.83691 143.057 3.83691 115.032C3.83691 104.122 6.35199 86.0893 13.8498 68.2185L0.224791 14.7463C-1.43728 6.14467 6.3705 -1.38586 15.2876 0.216682L66.3051 17.2859C74.8856 14.6362 84.5688 13.2176 95.4997 13.429C106.431 13.2176 116.114 14.6362 124.695 17.2859ZM174.699 124.569H153.569V80.6255C153.569 75.6157 151.762 72.1804 146.896 72.1804C143.143 72.1804 139.529 74.6137 135.775 78.3353V124.569H114.785V80.6255C114.785 75.6157 112.977 72.1804 108.112 72.1804C104.22 72.1804 100.744 74.6137 96.9909 78.3353V124.569H76V54.4314H94.4887L96.0178 64.0216C102.134 57.5804 108.39 53 117.148 53C126.462 53 131.605 57.7235 134.107 64.0216C140.224 57.7235 146.896 53 155.376 53C168.026 53 174.699 61.1588 174.699 74.7569V124.569ZM247.618 89.3569C247.618 91.5039 247.479 93.7941 247.201 94.9392H206.331C207.443 105.961 213.838 110.255 223.012 110.255C230.519 110.255 237.887 107.392 245.393 102.955L247.479 118.127C240.111 122.994 231.075 126 220.371 126C199.936 126 185.34 114.835 185.34 89.7863C185.34 66.8843 198.963 53 217.452 53C238.304 53 247.618 69.0314 247.618 89.3569ZM227.6 83.0588C226.905 72.4667 223.29 67.0274 216.896 67.0274C211.057 67.0274 206.887 72.3235 206.192 83.0588H227.6ZM288.054 126C306.96 126 321 111.973 321 89.5C321 67.0274 307.099 53 288.193 53C269.426 53 255.525 67.1706 255.525 89.6431C255.525 112.116 269.287 126 288.054 126ZM288.193 70.749C296.256 70.749 300.704 78.3353 300.704 89.6431C300.704 100.951 296.256 108.537 288.193 108.537C280.269 108.537 275.821 100.808 275.821 89.5C275.821 78.049 280.13 70.749 288.193 70.749Z" fill="currentColor"></path>
</svg>
<select id="login-language-sel" onchange="loginLang(this.value)">
<option value="en" ${language === "en" ? "selected" : ""}>${en.language}</option>
<option value="enuk" ${language === "enuk" ? "selected" : ""}>${enuk.language}</option>
<option value="es" ${language === "es" ? "selected" : ""}>${es.language}</option>
<option value="es_es" ${language === "es_es" ? "selected" : ""}>${es_es.language}</option>
<option value="fr" ${language === "fr" ? "selected" : ""}>${fr.language}</option>
<option value="de" ${language === "de" ? "selected" : ""}>${de.language}</option>
<option value="ua" ${language === "ua" ? "selected" : ""}>${ua.language}</option>
</select>
</div>
<div class="login-back">
<svg viewBox="0 0 640 241" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M640 125.573V240.972H0V0.0817643C55.9126 -1.18277 109.819 12.2262 158.654 39.893C178.197 51.0356 196.768 64.3924 215.342 77.752C231.898 89.6595 248.457 101.569 265.708 111.915C317.851 143.196 376.397 159.929 437.266 158.287C469.927 157.428 505.114 149.607 540.103 141.831C568.471 135.526 596.708 129.251 623.362 126.737C628.896 126.215 634.448 125.82 640 125.573Z" fill="currentColor"/>
</svg>
</div>
<div class='login-bottom'>
<a href="https://github.com/3r1s-s" target="_blank" class="info-button">
<svg viewBox="0 0 24 24" height="24" width="24" aria-hidden="true" focusable="false" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M12.026 2c-5.509 0-9.974 4.465-9.974 9.974 0 4.406 2.857 8.145 6.821 9.465.499.09.679-.217.679-.481 0-.237-.008-.865-.011-1.696-2.775.602-3.361-1.338-3.361-1.338-.452-1.152-1.107-1.459-1.107-1.459-.905-.619.069-.605.069-.605 1.002.07 1.527 1.028 1.527 1.028.89 1.524 2.336 1.084 2.902.829.091-.645.351-1.085.635-1.334-2.214-.251-4.542-1.107-4.542-4.93 0-1.087.389-1.979 1.024-2.675-.101-.253-.446-1.268.099-2.64 0 0 .837-.269 2.742 1.021a9.582 9.582 0 0 1 2.496-.336 9.554 9.554 0 0 1 2.496.336c1.906-1.291 2.742-1.021 2.742-1.021.545 1.372.203 2.387.099 2.64.64.696 1.024 1.587 1.024 2.675 0 3.833-2.33 4.675-4.552 4.922.355.308.675.916.675 1.846 0 1.334-.012 2.41-.012 2.737 0 .267.178.577.687.479C19.146 20.115 22 16.379 22 11.974 22 6.465 17.535 2 12.026 2z" clip-rule="evenodd"></path>
</svg>
</a>
<a href="https://discord.gg/gjdKksMjMs" target="_blank" class="info-button">
<svg width="24" height="24" viewBox="0 0 24 19" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20.3303 1.52336C18.7535 0.80145 17.0889 0.289302 15.3789 0C15.1449 0.418288 14.9332 0.848651 14.7447 1.28929C12.9233 1.01482 11.071 1.01482 9.24963 1.28929C9.06097 0.848696 8.84926 0.418339 8.61537 0C6.90435 0.291745 5.23861 0.805109 3.6602 1.52714C0.526645 6.16328 -0.322812 10.6843 0.101917 15.1411C1.937 16.4969 3.99099 17.5281 6.17459 18.1897C6.66627 17.5284 7.10135 16.8269 7.47521 16.0925C6.76512 15.8273 6.07977 15.5001 5.42707 15.1147C5.59885 14.9901 5.76685 14.8617 5.92919 14.7371C7.82839 15.6303 9.90126 16.0934 12 16.0934C14.0987 16.0934 16.1716 15.6303 18.0708 14.7371C18.235 14.8712 18.403 14.9995 18.5729 15.1147C17.9189 15.5007 17.2323 15.8285 16.521 16.0944C16.8944 16.8284 17.3295 17.5294 17.8216 18.1897C20.0071 17.5307 22.0626 16.5001 23.898 15.143C24.3964 9.97452 23.0467 5.49504 20.3303 1.52336ZM8.0132 12.4002C6.82962 12.4002 5.8518 11.3261 5.8518 10.0047C5.8518 8.68334 6.79564 7.59981 8.00942 7.59981C9.2232 7.59981 10.1935 8.68334 10.1727 10.0047C10.1519 11.3261 9.21943 12.4002 8.0132 12.4002ZM15.9868 12.4002C14.8013 12.4002 13.8273 11.3261 13.8273 10.0047C13.8273 8.68334 14.7711 7.59981 15.9868 7.59981C17.2024 7.59981 18.1652 8.68334 18.1444 10.0047C18.1236 11.3261 17.193 12.4002 15.9868 12.4002Z" fill="currentColor"/>
</svg>
</a>
<a href="https://eris.pages.dev" target="blank" class="info-button">
<svg width="13" height="14" viewBox="0 0 13 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.1016 8.99219L12.2812 9.26172C11.9375 10.5352 11.3008 11.5234 10.3711 12.2266C9.44141 12.9297 8.25391 13.2812 6.80859 13.2812C4.98828 13.2812 3.54297 12.7227 2.47266 11.6055C1.41016 10.4805 0.878906 8.90625 0.878906 6.88281C0.878906 4.78906 1.41797 3.16406 2.49609 2.00781C3.57422 0.851562 4.97266 0.273438 6.69141 0.273438C8.35547 0.273438 9.71484 0.839844 10.7695 1.97266C11.8242 3.10547 12.3516 4.69922 12.3516 6.75391C12.3516 6.87891 12.3477 7.06641 12.3398 7.31641H3.05859C3.13672 8.68359 3.52344 9.73047 4.21875 10.457C4.91406 11.1836 5.78125 11.5469 6.82031 11.5469C7.59375 11.5469 8.25391 11.3438 8.80078 10.9375C9.34766 10.5312 9.78125 9.88281 10.1016 8.99219ZM3.17578 5.58203H10.125C10.0312 4.53516 9.76562 3.75 9.32812 3.22656C8.65625 2.41406 7.78516 2.00781 6.71484 2.00781C5.74609 2.00781 4.92969 2.33203 4.26562 2.98047C3.60938 3.62891 3.24609 4.49609 3.17578 5.58203Z" fill="currentColor"/>
</svg>
</a>
<div class="info-bullet"></div>
<a href="https://meower.org/legal" target="_blank" class="info-link">
${lang().login_sub.agreement}
</a>
</div>
<div id='msgs'></div>
</div>
`;
}
function toggleSignUp(to) {
if (to) {
document.querySelector(".login-inner").innerHTML = `
<h2 id="login-header" class="login-header">${lang().meo_welcome}</h2>
<input type="text" id="userinput" placeholder="${lang().meo_username}" class="login-text text" aria-label="username input" autocomplete="username">
<input type="password" id="passinput" placeholder="${lang().meo_password}" class="login-text text" aria-label="password input" autocomplete="current-password">
<input type="text" id="otpinput" placeholder="${lang().meo_totp}" class="login-text text" aria-label="one-time-code input" autocomplete="one-time-code" style="display:none;">
<input type="button" id="login" value="${lang().action.login}" class="login-button button" onclick="toggleLogin(true);login()" aria-label="Register">
<input type="button" id="signup" value="${lang().action.signup}" class="login-button button" onclick="agreementModal()" aria-label="log in" style="display:none;">
<input type="button" id="back" value="${lang().action.back}" class="login-button button" onclick="loadLogin()" aria-label="back" style="display:none;">
<div class="login-sub">
<a onclick="toggleSignUp(false)" id="togglesignup">${lang().action.signup}</a>
<small>${lang().login_sub.desc}</small>
</div>
`;
} else {
document.querySelector(".login-inner").innerHTML = `
<h2 id="login-header" class="login-header">${lang().meo_hello}</h2>
<input type="text" id="userinput" placeholder="${lang().meo_username}" class="login-text text" aria-label="username input" autocomplete="username">
<input type="password" id="passinput" placeholder="${lang().meo_password}" class="login-text text" aria-label="password input" autocomplete="current-password">
<input type="button" id="login" value="${lang().action.login}" class="login-button button" onclick="toggleLogin(true);login()" aria-label="Register" style="display:none;">
<input type="button" id="signup" value="${lang().action.signup}" class="login-button button" onclick="agreementModal()" aria-label="log in">
<div class="login-sub">
<a onclick="toggleSignUp(true)" id="togglesignup">${lang().action.login}</a>
<small>${lang().login_sub.desc}</small>
</div>
`;
}
}
function loadpost(p) {
let user;
let content;
let bridged = (p.u && bridges.includes(p.u));
if (bridged) {
const rcon = p.p;
const match = rcon.match(/^([a-zA-Z0-9_-]{1,20})?:([\s\S]+)?/m);
if (match) {
user = match[1];
content = match[2] || "";
} else {
user = p.u;
content = rcon;
}
} else {
if (p.u === "Webhooks") {
const rcon = p.p;
const parts = rcon.split(': ');
user = parts[0];
content = parts.slice(1).join(': ');
} else {
content = p.p;
user = p.u;
}
}
const postContainer = document.createElement("div");
postContainer.classList.add("post");
postContainer.setAttribute("tabindex", "0");
const ba = Object.keys(blockedWords);
const bc = ba.some(word => {
const regex = new RegExp('\\b' + word + '\\b', 'i');
return regex.test(content);
});
if (bc) {
if (settingsstuff().censorwords) {
content = content.replace(new RegExp('\\b(' + ba.join('|') + ')\\b', 'gi'), match => '*'.repeat(match.length));
} else {
if (settingsstuff().blockedmessages) {
postContainer.setAttribute("style", "display:none;");
} else {
postContainer.classList.add("blocked");
}
}
}
if (blockedUsers.hasOwnProperty(user)) {
if (settingsstuff().blockedmessages) {
postContainer.setAttribute("style", "display:none;");
} else {
postContainer.classList.add("blocked");
}
}
const wrapperDiv = document.createElement("div");
wrapperDiv.classList.add("wrapper");
const pfpDiv = document.createElement("div");
pfpDiv.classList.add("pfp");
if (p.post_origin !== "livechat") {
postContainer.appendChild(createButtonContainer(p));
const mobileButtonContainer = document.createElement("div");
mobileButtonContainer.classList.add("mobileContainer");
mobileButtonContainer.innerHTML = `
<div class='toolbarContainer'>
${p.post_origin !== 'inbox' && page !== "recent" ? `<div class='toolButton mobileButton' onclick='reply("${p._id}")' aria-label="reply" title="reply" tabindex="0">
<svg width='24' height='24' viewBox='0 0 24 24'><path d='M10 8.26667V4L3 11.4667L10 18.9333V14.56C15 14.56 18.5 16.2667 21 20C20 14.6667 17 9.33333 10 8.26667Z' fill='currentColor'></path></svg>
</div>` : ''}
<div class='toolButton mobileButton' onclick='openModal("${p._id}");'>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" d="M4 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm8 0a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z" clip-rule="evenodd" class=""></path></svg>
</div>
</div>
`;
postContainer.appendChild(mobileButtonContainer);
}
const pstdte = document.createElement("i");
pstdte.classList.add("date");
tsr = p.t.e;
tsra = tsr * 1000;
tsrb = Math.trunc(tsra);
const ts = new Date();
ts.setTime(tsrb);
pstdte.innerText = new Date(tsrb).toLocaleString([], { month: '2-digit', day: '2-digit', year: '2-digit', hour: 'numeric', minute: 'numeric' });
const pstinf = document.createElement("span");
pstinf.classList.add("user-header")
pstinf.innerHTML = `<span id='username' onclick='openUsrModal("${user}")' data-user-title='${user}'>${user}</span>`;
if (bridged || p.u == "Webhooks") {
const bridged = document.createElement("bridge");
bridged.innerText = lang().meo_bridged.start;
bridged.setAttribute("title", lang().meo_bridged.title);
pstinf.appendChild(bridged);
}
pstinf.appendChild(pstdte);
wrapperDiv.appendChild(pstinf);
const roarer = /@([\w-]+)\s+"([^"]*)"\s+\(([^)]+)\)/g;
const bettermeower = /@([\w-]+)\[([a-zA-Z0-9]+)\]/g;
let matches1 = [...content.matchAll(roarer)];
let matches2 = [...content.matchAll(bettermeower)];
let allMatches = matches1.concat(matches2);
if (allMatches.length > 0) {
const replyIds = allMatches.map(match => match[3] || match[2]);
const pageContainer = document.getElementById("msgs");
if (pageContainer.firstChild) {
pageContainer.insertBefore(postContainer, pageContainer.firstChild);
} else {
pageContainer.appendChild(postContainer);
}
loadreplies(p.post_origin, replyIds).then(replyContainers => {
replyContainers.forEach(replyContainer => {
pstinf.after(replyContainer);
});
});
allMatches.forEach(match => {
content = content.replace(match[0], '').trim();
});
}
const repliesContainer = document.createElement("div");
p.reply_to.forEach((item) => repliesContainer.appendChild(loadreplyv(item)));
pstinf.after(repliesContainer);
let postContentText = document.createElement("p");
postContentText.className = "post-content";
// tysm tni <3
if (typeof md !== 'undefined') {
md.disable(['image']);
postContentText.innerHTML = erimd(md.render(content));
postContentText.innerHTML = meowerEmojis(postContentText.innerHTML, p.emojis || []);
postContentText.innerHTML = buttonbadges(postContentText);
} else {
// fallback for when md doenst work
// figure this issue OUT
postContentText.innerHTML = oldMarkdown(content);
console.error("Parsed with old markdown, fix later :)")
}
const emojiRgx = /^(?:(?!\d)(?:\p{Emoji}|[\u200d\ufe0f\u{E0061}-\u{E007A}\u{E007F}]))+$/u;
const meowerRgx = /^<:[a-zA-Z0-9]{24}>$/g;
const discordRgx = /^<(a)?:\w+:\d+>$/gi;
if (emojiRgx.test(content) || (meowerRgx.test(content) && p.emojis.length) || discordRgx.test(content)) {
postContentText.classList.add('big');
}
if (content) {
wrapperDiv.appendChild(postContentText);
}
const links = content.match(/(?:https?|ftp):\/\/[^\s(){}[\]]+/g);
const embd = embed(links);
if (embd || p.attachments) {
const embedsDiv = document.createElement('div');
embedsDiv.classList.add('embeds');
if (embd) {
embd.forEach(embeddedElement => {
embedsDiv.appendChild(embeddedElement);
});
}
p.attachments.forEach(attachment => {
const g = attach(attachment);
embedsDiv.appendChild(g);
});
wrapperDiv.appendChild(embedsDiv);
}
postContainer.appendChild(wrapperDiv);
loadPfp(user, p.author, 0)
.then(pfpElement => {
if (pfpElement) {
pfpDiv.appendChild(pfpElement);
pfpCache[user] = pfpElement.cloneNode(true);
postContainer.insertBefore(pfpDiv, wrapperDiv);
}
});
const placeholder = document.getElementById(`placeholder-${p.nonce}`);
if (placeholder) placeholder.remove();
const pageContainer = document.getElementById("msgs");
const existingPost = document.getElementById(p._id);
postContainer.id = p._id;
if (existingPost) {
existingPost.replaceWith(postContainer);
} else if (pageContainer.firstChild && p._top) {
pageContainer.insertBefore(postContainer, pageContainer.firstChild);
} else {
pageContainer.appendChild(postContainer);
}
}
function loadPfp(username, userData, button) {
return new Promise(async (resolve, reject) => {
if (pfpCache[username]) {
resolve(pfpCache[username].cloneNode(true));
} else {
let pfpElement;
if (!userData) {
try {
const resp = await fetch(`https://api.meower.org/users/${username}`);
userData = await resp.json();
} catch (error) {
console.error("Failed to fetch:", error);
resolve(null);
}
}
if (userData.avatar) {
const pfpurl = `https://uploads.meower.org/icons/${userData.avatar}`;
pfpElement = document.createElement("div");
pfpElement.style.backgroundImage = `url(${pfpurl})`;
pfpElement.classList.add("pfp-inner");
pfpElement.setAttribute("alt", username);
pfpElement.setAttribute("data-username", username);
pfpElement.classList.add("avatar");
if (!button) {
pfpElement.setAttribute("onclick", `openUsrModal('${username}')`);
}
if (userData.avatar_color) {
// if (userData.avatar_color === "!color") {
// pfpElement.style.border = `3px solid #f00`;
// pfpElement.style.backgroundColor = `#f00`;
// } else {
// }
pfpElement.style.border = `3px solid #${userData.avatar_color}`;
pfpElement.style.backgroundColor = `#${userData.avatar_color}`;
}
pfpElement.addEventListener('error', function pngFallback() {
pfpElement.removeEventListener('error', pngFallback);
pfpElement.setAttribute("src", `${pfpurl}.png`);
pfpCache[username].setAttribute("src", `${pfpurl}.png`);
});
} else if (userData.pfp_data) {
let pfpurl;
if (userData.pfp_data > 0 && userData.pfp_data <= 37) {
pfpurl = `images/avatars/icon_${userData.pfp_data - 1}.svg`;
} else {
pfpurl = `images/avatars/icon_err.svg`;
}
pfpElement = document.createElement("div");
pfpElement.style.backgroundImage = `url(${pfpurl})`;
pfpElement.classList.add("pfp-inner");
pfpElement.setAttribute("alt", username);
pfpElement.setAttribute("data-username", username);
pfpElement.classList.add("avatar");
if (!button) {
pfpElement.setAttribute("onclick", `openUsrModal('${username}')`);
}
pfpElement.classList.add("svg-avatar");
if (userData.avatar_color) {
pfpElement.style.border = `3px solid #${userData.avatar_color}`;
}
} else {
const pfpurl = `images/avatars/icon_-4.svg`;
pfpElement = document.createElement("div");
pfpElement.style.backgroundImage = `url(${pfpurl})`;
pfpElement.classList.add("pfp-inner");
pfpElement.setAttribute("alt", username);
pfpElement.setAttribute("data-username", username);
if (!button) {
pfpElement.setAttribute("onclick", `openUsrModal('${username}')`);
}
pfpElement.classList.add("avatar");
pfpElement.classList.add("svg-avatar");
pfpElement.style.border = `3px solid #fff`;
pfpElement.style.backgroundColor = `#fff`;
}
if (pfpElement) {
pfpCache[username] = pfpElement.cloneNode(true);
}
resolve(pfpElement);
}
});
}
async function loadreplies(postOrigin, replyIds) {
const replies = await Promise.all(replyIds.map(replyid => loadreply(postOrigin, replyid)));
return replies;
}
async function loadreply(postOrigin, replyid) {
const roarRegex = /^@[\w-]+ (.+?) \(([^)]+)\)/;
try {
let replydata = postCache[postOrigin].find(post => post._id === replyid);
if (!replydata) {
const replyresp = await fetch(`https://api.meower.org/posts?id=${replyid}`, {
headers: { token: localStorage.getItem("token") }
});
if (replyresp.status === 404) {
replydata = { p: "[original message was deleted]" };
} else {
replydata = await replyresp.json();
}
}
let bridged = (bridges.includes(replydata.u));
const replycontainer = document.createElement("div");
replycontainer.style.setProperty('--reply-accent', "var(--accent-down)");
replycontainer.classList.add("reply");