-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathrevertlogo.js
More file actions
895 lines (800 loc) · 36.1 KB
/
Copy pathrevertlogo.js
File metadata and controls
895 lines (800 loc) · 36.1 KB
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
import { observeElement } from '../../core/observer.js';
import { fetchThumbnails } from '../../core/thumbnail/thumbnails.js';
<<<<<<< HEAD
import { loadDatacenterMap, serverIpMap } from '../../core/regions.js';
=======
import {
loadDatacenterMap,
getRegionData,
serverIpMap,
} from '../../core/regions.js';
>>>>>>> ba4b86e (cleanup: linting autofix)
import { callRobloxApi } from '../../core/api.js';
import DOMPurify from 'dompurify';
import { launchGame } from '../../core/utils/launcher.js';
import { t, ts } from '../../core/locale/i18n.js';
import {
fetchServerDetails,
fetchServerRegion,
getServerUptime,
getServerUptimeIsEstimate,
formatUptime,
} from '../../core/apis/serverApi.js';
import {
showLoadingOverlay,
updateLoadingOverlayText,
updateServerInfo,
showLoadingOverlayResult,
hideLoadingOverlay,
} from '../../core/ui/startModal/gamelaunchmodal.js';
const HIDE_ROBLOX_UI_CLASS = 'rovalra-hide-roblox-dialogs';
const styles = `
body.${HIDE_ROBLOX_UI_CLASS} .foundation-web-dialog-overlay,
body.${HIDE_ROBLOX_UI_CLASS} .MuiModal-root,
body.${HIDE_ROBLOX_UI_CLASS} .ReactModalPortal,
body.${HIDE_ROBLOX_UI_CLASS} iframe#gamelaunch {
display: none !important;
visibility: hidden !important;
pointer-events: none !important;
opacity: 0 !important;
z-index: -9999 !important;
}
.rovalra-info-icon {
fill: rgb(32, 34, 39);
}
.dark-theme .rovalra-info-icon {
fill: rgb(247, 247, 248) !important;
}
.light-theme .rovalra-info-icon {
fill: rgb(32, 34, 39) !important;
}
`;
try {
const styleSheet = document.createElement('style');
styleSheet.textContent = styles;
(document.head || document.documentElement).appendChild(styleSheet);
} catch (e) {}
function openInterface(onCancel, customLogo, closeOnBackgroundClick) {
document.body.classList.add(HIDE_ROBLOX_UI_CLASS);
showLoadingOverlay(
() => {
closeInterface();
if (onCancel) onCancel();
},
customLogo,
closeOnBackgroundClick,
);
}
function closeInterface(force = false) {
document.body.classList.remove(HIDE_ROBLOX_UI_CLASS);
hideLoadingOverlay(force);
}
let lastProcessedGameLaunchSrc = null;
let gameLaunchElementExists = false;
let interceptedServerData = null;
let currentGameId = null;
let pollingInterval = null;
let clientStatusReceived = false;
function cleanupPolling() {
if (pollingInterval) {
clearInterval(pollingInterval);
pollingInterval = null;
}
document.removeEventListener(
'rovalra-game-launch-success',
handleGameLaunchSuccess,
);
}
function triggerSuccess() {
if (!clientStatusReceived) {
clientStatusReceived = true;
cleanupPolling();
showLoadingOverlayResult(ts('revertLogo.haveFun'), {
text: ts('revertLogo.close'),
onClick: () => {
cleanupPolling();
closeInterface(true);
},
});
}
}
function handleGameLaunchSuccess() {
triggerSuccess();
}
async function ensureDatacenterDataIsParsed() {
try {
if (Object.keys(serverIpMap).length > 0) return;
await loadDatacenterMap();
await getRegionData();
} catch (error) {
console.warn('Rovalra: Failed to load datacenter map', error);
}
}
async function fetchGameDetails(placeId) {
if (!placeId)
return { name: await t('revertLogo.robloxExperience'), iconUrl: null };
try {
const detailsReq = await callRobloxApi({
endpoint: `/v1/games/multiget-place-details?placeIds=${placeId}`,
subdomain: 'games',
});
const detailsData = await detailsReq.json();
const name =
detailsData[0]?.name || (await t('revertLogo.unknownExperience'));
let iconUrl = null;
try {
const thumbMap = await fetchThumbnails(
[{ id: parseInt(placeId, 10) }],
'PlaceIcon',
'150x150',
false,
);
const thumbData = thumbMap.get(parseInt(placeId, 10));
if (thumbData && thumbData.state === 'Completed') {
iconUrl = thumbData.imageUrl;
}
} catch (e) {}
return { name, iconUrl };
} catch (e) {
return { name: await t('revertLogo.robloxExperience'), iconUrl: null };
}
}
function attachLiveUptimeListener() {
const el = document.querySelector('.rovalra-live-uptime');
if (el && !el._rovalraUptimeHooked) {
el._rovalraUptimeHooked = true;
el.addEventListener('rovalra-uptime-update', (e) => {
const valEl = el.querySelector('.uptime-value');
if (valEl) {
valEl.textContent = formatUptime(
e.detail.uptime,
e.detail.isEstimate,
);
}
});
}
}
async function fetchUserPresence(userId) {
if (!userId) return null;
try {
const response = await callRobloxApi({
subdomain: 'presence',
endpoint: '/v1/presence/users',
method: 'POST',
body: { userIds: [parseInt(userId, 10)] },
});
if (!response.ok) return null;
const data = await response.json();
return (
data?.userPresences?.[0]?.rootPlaceId ||
data?.userPresences?.[0]?.placeId ||
null
);
} catch {
return null;
}
}
const buildInfoList = (
gameId,
isPrivateServer,
regionCode,
regionName,
serverInfo,
placeVersion,
serverChannel,
rccVersion,
ownerInfo,
) => {
const liClass = `class="rovalra-details-li"`;
const verIcon = `<svg class="rovalra-info-icon" viewBox="0 0 24 24"><path d="M21 10.12h-6.78l2.74-2.82c-2.73-2.7-7.15-2.8-9.88-.1-2.73 2.71-2.73 7.08 0 9.79s7.15 2.71 9.88 0C18.32 15.65 19 14.08 19 12.1h2c0 1.98-.88 4.55-2.64 6.29-3.51 3.48-9.21 3.48-12.72 0-3.5-3.47-3.53-9.11-.02-12.58s9.14-3.47 12.65 0L21 3zM12.5 8v4.25l3.5 2.08-.72 1.21L11 13V8z"></path></svg>`;
const timeIcon = `<svg class="rovalra-info-icon" viewBox="0 0 24 24"><path d="m22 5.7-4.6-3.9-1.3 1.5 4.6 3.9zM7.9 3.4 6.6 1.9 2 5.7l1.3 1.5zM12.5 8H11v6l4.7 2.9.8-1.2-4-2.4zM12 4c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9m0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7"></path></svg>`;
const rccIcon = `<svg class="rovalra-info-icon" viewBox="0 0 24 24"><path d="M21 3H3c-1.11 0-2 .89-2 2v12c0 1.1.89 2 2 2h5v2h8v-2h5c1.1 0 1.99-.9 1.99-2L23 5c0-1.11-.9-2-2-2m0 14H3V5h18z"></path></svg>`;
const privIcon = `<svg class="rovalra-info-icon" viewBox="0 0 24 24"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2m-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2m3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1s3.1 1.39 3.1 3.1z"></path></svg>`;
const channelIcon = `<svg class="rovalra-info-icon" viewBox="0 0 24 24"><path d="M15 9H9v6h6zm-2 4h-2v-2h2zm8-2V9h-2V7c0-1.1-.9-2-2-2h-2V3h-2v2h-2V3H9v2H7c-1.1 0-2 .9-2 2v2H3v2h2v2H3v2h2v2c0 1.1.9 2 2 2h2v2h2v-2h2v2h2v-2h2c1.1 0 2-.9 2-2v-2h2v-2h-2v-2zm-4 6H7V7h10z"></path></svg>`;
const listItems = [];
if (gameId) {
listItems.push(
`<li style="white-space: nowrap;" ${liClass}><strong>${ts('revertLogo.serverId')}</strong> <span class="rovalra-spoiler" style="white-space: nowrap;">${gameId}</span></li>`,
);
}
if (isPrivateServer)
listItems.push(
`<li ${liClass}>${privIcon}<strong>${ts('revertLogo.privateServer')}</strong></li>`,
);
if (ownerInfo) {
const ownerProfileUrl = `https://www.roblox.com/users/${ownerInfo.id}/profile`;
const ownerIconHtml = ownerInfo.thumbnailUrl
? `<img src="${ownerInfo.thumbnailUrl}" style="width:16px;height:16px;border-radius:50%;margin-right:6px;vertical-align:text-bottom;" alt="Owner">`
: `<span style="width:16px;height:16px;border-radius:50%;margin-right:6px;background-color:#555;display:inline-block;vertical-align:text-bottom;"></span>`;
listItems.push(
`<li ${liClass}>${ownerIconHtml}<strong>${ts('revertLogo.owner')}</strong> <a href="${ownerProfileUrl}" target="_blank" style="text-decoration: underline;">${ownerInfo.displayName}</a></li>`,
);
}
if (regionCode && regionName) {
const flagCountryCode = regionCode.toLowerCase().split('-')[0];
const flagUrl = `https://flagcdn.com/w20/${flagCountryCode}.png`;
listItems.push(
`<li ${liClass}><img src="${flagUrl}" alt="${regionCode}"> ${regionName}</li>`,
);
}
if (placeVersion)
listItems.push(
`<li ${liClass}>${verIcon} <strong>${ts('revertLogo.version')}</strong> ${placeVersion}</li>`,
);
const uptime = getServerUptime(gameId);
if (uptime !== null) {
const isEstimate = getServerUptimeIsEstimate(gameId);
const uptimeStr = formatUptime(uptime, isEstimate);
listItems.push(
`<li class="rovalra-details-li rovalra-live-uptime" data-rovalra-serverid="${gameId}">${timeIcon} <strong>${ts('revertLogo.uptime')}</strong> <span class="uptime-value">${uptimeStr}</span></li>`,
);
}
if (rccVersion)
listItems.push(
`<li ${liClass}>${rccIcon} <strong>${ts('revertLogo.rcc')}</strong> ${rccVersion}</li>`,
);
const channelText = serverChannel || ts('revertLogo.production');
listItems.push(`
<li ${liClass}>
${channelIcon}
<strong>${ts('revertLogo.serverChannel')}</strong>
<div class="rovalra-channel-wrapper">
<span class="rovalra-channel-truncated">${channelText}</span>
<span class="rovalra-channel-tooltip">${channelText}</span>
</div>
</li>
`);
return DOMPurify.sanitize(listItems.join(''));
};
async function pollClientStatus(targetPlaceId) {
clientStatusReceived = false;
cleanupPolling();
let isDownloadOptionShown = false;
let unknownStatusCount = 0;
const triggerDownloadOption = () => {
if (!clientStatusReceived && !isDownloadOptionShown) {
isDownloadOptionShown = true;
showLoadingOverlayResult(ts('revertLogo.launchingRoblox'), {
text: ts('revertLogo.downloadRoblox'),
onClick: showDownloadUI,
});
setTimeout(() => {
const buttons = document.querySelectorAll('button');
for (const btn of buttons) {
if (
btn.textContent.includes(
ts('revertLogo.downloadRoblox'),
)
) {
const wrapper = document.createElement('div');
wrapper.innerHTML = DOMPurify.sanitize(
`<button type="button" class="foundation-web-button relative clip group/interactable focus-visible:outline-focus disabled:outline-none cursor-pointer relative flex items-center justify-center stroke-none padding-y-none select-none radius-medium text-label-medium height-1000 padding-x-medium bg-action-emphasis content-action-emphasis grow" style="text-decoration: none;"><div role="presentation" class="absolute inset-[0] transition-colors group-hover/interactable:bg-[var(--color-state-hover)] group-active/interactable:bg-[var(--color-state-press)] group-disabled/interactable:bg-none"></div><span class="padding-y-xsmall text-truncate-end text-no-wrap">${ts('revertLogo.downloadRoblox')}</span></button>`,
);
const newBtn = wrapper.firstChild;
if (newBtn) {
newBtn.onclick = showDownloadUI;
btn.replaceWith(newBtn);
}
break;
}
}
}, 50);
}
};
const showDownloadUI = () => {
if (document.getElementById('rovalra-download-dialog-container'))
return;
const startDownload = () => {
window.open(
`https://www.roblox.com/download/client?_=${Date.now()}`,
'_blank',
);
};
startDownload();
hideLoadingOverlay();
const dialogWrapper = document.createElement('div');
dialogWrapper.id = 'rovalra-download-dialog-container';
dialogWrapper.style.cssText =
'position: fixed; inset: 0; z-index: 99999; display: flex; align-items: center; justify-content: center; background-color: rgba(0,0,0,0.6);';
// Roblox download ui
dialogWrapper.innerHTML = DOMPurify.sanitize(
`<div role="dialog" id="radix-0" aria-describedby="radix-2" aria-labelledby="radix-1" data-state="open" class="relative radius-large bg-surface-100 stroke-muted stroke-standard foundation-web-dialog-content shadow-transient-high install-dialog" data-size="Large" tabindex="-1" style="pointer-events: auto;"><div class="absolute foundation-web-dialog-close-container"><button type="button" class="foundation-web-close-affordance flex stroke-none bg-none cursor-pointer relative clip group/interactable focus-visible:outline-focus disabled:outline-none bg-over-media-100 padding-medium radius-circle" aria-label="Close"><div role="presentation" class="absolute inset-[0] transition-colors group-hover/interactable:bg-[var(--color-state-hover)] group-active/interactable:bg-[var(--color-state-press)] group-disabled/interactable:bg-none"></div><span role="presentation" class="grow-0 shrink-0 basis-auto icon icon-regular-x size-[var(--icon-size-large)]"></span></button></div><div class="padding-x-xlarge padding-top-xlarge padding-bottom-xlarge content-default"><div class="flex flex-col gap-xlarge padding-xlarge"><div class="flex flex-col gap-xsmall"><h2 id="radix-1" class="text-heading-medium content-emphasis padding-none">${ts('revertLogo.thanksDownloading')}</h2><p class="text-body-large">${ts('revertLogo.downloadInstructions')}</p></div><div></div> <div class="flex gap-xxlarge"><section class="flex flex-col gap-large grow basis-0"><h3 class="text-title-large content-emphasis padding-none">${ts('revertLogo.installInstructions')}</h3><ol class="download-instructions-list flex flex-col gap-xlarge margin-none padding-left-large text-body-medium"><li class="padding-left-medium">${ts('revertLogo.step1')}</li><li class="padding-left-medium">${ts('revertLogo.step2')}</li><li class="padding-left-medium">${ts('revertLogo.step3')}</li><li class="padding-left-medium">${ts('revertLogo.step4')}</li></ol></section><div></div> <div class="stroke-standard stroke-default"></div><div></div> <section class="flex flex-col grow basis-0 gap-xxlarge"><div class="flex flex-col gap-small"><h3 class="text-label-large content-emphasis padding-none">${ts('revertLogo.mobileApp')}</h3><p class="text-body-medium">${ts('revertLogo.scanCode')}</p></div><div class="flex grow justify-center items-center bg-shift-100 radius-medium padding-x-large"><div class="radius-medium padding-small bg-[white]"><img class="size-2100" src="https://images.rbxcdn.com/79852c254bf43f36.webp" alt=""></div></div></section></div></div></div></div>`,
{ ADD_ATTR: ['id'] },
);
document.body.appendChild(dialogWrapper);
const closeDialog = () => {
dialogWrapper.remove();
closeInterface(true);
};
const closeBtn = dialogWrapper.querySelector(
'button[aria-label="Close"]',
);
if (closeBtn) closeBtn.onclick = closeDialog;
const joinLink = dialogWrapper.querySelector(
'#download-join-experience',
);
if (joinLink) {
joinLink.onclick = (e) => {
e.preventDefault();
closeDialog();
if (targetPlaceId) launchGame(targetPlaceId);
};
}
const restartLink = dialogWrapper.querySelector(
'#rovalra-restart-download',
);
if (restartLink) {
restartLink.onclick = (e) => {
e.preventDefault();
startDownload();
};
}
};
const performClientStatusCheck = async () => {
try {
const response = await callRobloxApi({
subdomain: 'apis',
endpoint: '/matchmaking-api/v1/client-status',
method: 'GET',
noCache: true,
});
if (response.ok) {
const data = await response.json();
handleClientStatus(data);
}
} catch {}
};
const handleClientStatus = (data) => {
if (data && data.status) {
if (data.status === 'Unknown') {
unknownStatusCount++;
if (unknownStatusCount >= 3) {
triggerDownloadOption();
} else {
setTimeout(() => {
performClientStatusCheck();
}, 1000);
}
} else {
unknownStatusCount = 0;
if (isDownloadOptionShown) {
isDownloadOptionShown = false;
updateLoadingOverlayText(ts('revertLogo.joiningServer'));
}
if (data.status === 'InGame') {
triggerSuccess();
}
}
}
};
document.addEventListener(
'rovalra-game-launch-success',
handleGameLaunchSuccess,
);
const currentUserElement = document.querySelector('meta[name="user-data"]');
const currentUserId = currentUserElement
? currentUserElement.dataset.userid
: null;
if (currentUserId) {
performClientStatusCheck();
pollingInterval = setInterval(async () => {
if (
!document.body.classList.contains(HIDE_ROBLOX_UI_CLASS) ||
clientStatusReceived
) {
cleanupPolling();
return;
}
performClientStatusCheck();
try {
const resp = await callRobloxApi({
subdomain: 'presence',
endpoint: '/v1/presence/users',
method: 'POST',
body: { userIds: [parseInt(currentUserId, 10)] },
});
if (resp.ok) {
const data = await resp.json();
const presence = data?.userPresences?.[0];
if (
presence &&
(presence.userPresenceType === 2 ||
presence.userPresenceType === 4)
) {
if (
targetPlaceId &&
presence.rootPlaceId === parseInt(targetPlaceId, 10)
) {
triggerSuccess();
} else if (!targetPlaceId) {
triggerSuccess();
}
}
}
} catch {}
}, 3000);
}
}
const customLogoId = 'rovalra-custom-logo';
const targetSelectors = [
'span.app-icon-bluebg.app-icon-windows.app-icon-size-96',
'div.MuiGrid-root div.app-icon-bluebg.app-icon-windows',
'.app-icon-windows.app-icon-bluebg',
];
function applyCustomLogo(imageData, element) {
if (element) {
const size =
element.closest("div[role='dialog']") ||
element.closest('.MuiDialog-paper')
? { width: '64px', height: '64px' }
: { width: '96px', height: '96px' };
if (element.id === customLogoId) {
Object.assign(element.style, size);
return;
}
const img = document.createElement('img');
img.id = customLogoId;
img.src = imageData;
Object.assign(img.style, { ...size, objectFit: 'contain' });
element.replaceWith(img);
}
}
function initRevertLogo() {
chrome.storage.local.get(
{ revertLogo: false, customLogoData: null },
(settings) => {
if (settings.revertLogo === true && settings.customLogoData) {
const callback = (el) =>
applyCustomLogo(settings.customLogoData, el);
targetSelectors.forEach((selector) =>
observeElement(selector, callback),
);
}
},
);
}
function initializeJoinDialogEnhancer() {
document.addEventListener('rovalra-game-servers-response', (event) => {
const { data } = event.detail;
if (data && data.data && Array.isArray(data.data) && currentGameId) {
const server = data.data.find((s) => s.id === currentGameId);
if (server) {
interceptedServerData = {
playing: server.playing,
maxPlayers: server.maxPlayers,
fps: server.fps,
ping: server.ping,
};
}
}
});
chrome.storage.local.get(
{
whatamIJoiningEnabled: true,
AlwaysGetInfo: false,
customLogoData: null,
revertLogo: false,
closeUiByClickingTheBackground: true,
},
(settings) => {
const processGameLaunchData = async (gameLaunchFrame) => {
gameLaunchElementExists = true;
const gameLaunchSrc = gameLaunchFrame?.src;
if (
!gameLaunchSrc ||
!gameLaunchSrc.includes('placelauncherurl:') ||
gameLaunchSrc === lastProcessedGameLaunchSrc
)
return;
lastProcessedGameLaunchSrc = gameLaunchSrc;
currentGameId = null;
interceptedServerData = null;
const logoToUse =
settings.revertLogo === true && settings.customLogoData
? settings.customLogoData
: null;
openInterface(
null,
logoToUse,
settings.closeUiByClickingTheBackground,
);
let urlParams;
let placeId;
try {
const urlString = gameLaunchSrc.substring(
gameLaunchSrc.indexOf('placelauncherurl:'),
);
const decodedUrlString = decodeURIComponent(
urlString.split('+')[0].substring(17),
);
urlParams = new URLSearchParams(
new URL(decodedUrlString).search,
);
placeId = urlParams.get('placeId');
} catch {
showLoadingOverlayResult(
await t('revertLogo.errorParsingUrl'),
{
text: await t('revertLogo.close'),
onClick: () => closeInterface(true),
},
);
return;
}
if (
!placeId &&
urlParams.get('request') === 'RequestFollowUser'
) {
const userId = urlParams.get('userId');
if (userId) {
updateLoadingOverlayText(
await t('revertLogo.findingUser'),
);
placeId = await fetchUserPresence(userId);
}
}
let gameDetailsPromise = Promise.resolve({
name: await t('revertLogo.robloxExperience'),
iconUrl: null,
});
if (placeId) {
gameDetailsPromise = fetchGameDetails(placeId);
}
const requestType = urlParams.get('request');
const isRequestGame =
requestType === 'RequestGame' ||
requestType === 'RequestGameJob';
const hasGameId = urlParams.has('gameId');
const hasAccessCode = urlParams.has('accessCode');
const isGenericJoin =
isRequestGame && !hasGameId && !hasAccessCode;
const isPrivateServer = requestType === 'RequestPrivateGame';
const isFollowingUser = requestType === 'RequestFollowUser';
if (hasGameId) {
currentGameId = urlParams.get('gameId');
}
let joinApiResponse = null;
if (settings.AlwaysGetInfo) {
updateLoadingOverlayText(
await t('revertLogo.fetchingServerInfo'),
);
try {
await ensureDatacenterDataIsParsed();
let retries = 0;
const MAX_RETRIES = 5;
while (
!joinApiResponse &&
document.body.classList.contains(
HIDE_ROBLOX_UI_CLASS,
) &&
retries < MAX_RETRIES
) {
retries++;
try {
let data = null;
const apiBody = {
gameJoinAttemptId: crypto.randomUUID(),
placeId: parseInt(placeId, 10),
};
if (isGenericJoin) {
const response = await callRobloxApi({
subdomain: 'gamejoin',
endpoint: '/v1/join-game',
method: 'POST',
body: apiBody,
});
if (response.ok)
data = await response.json();
} else if (isPrivateServer) {
data = await fetchServerRegion(
placeId,
null,
{
isPrivate: true,
accessCode:
urlParams.get('accessCode'),
linkCode:
urlParams.get('linkCode'),
},
);
} else if (isFollowingUser) {
const userIdToFollow =
urlParams.get('userId');
const response = await callRobloxApi({
subdomain: 'gamejoin',
endpoint: '/v1/play-with-user',
method: 'POST',
body: {
userIdToFollow: parseInt(
userIdToFollow,
10,
),
},
});
if (response.ok)
data = await response.json();
} else if (currentGameId) {
data = await fetchServerRegion(
placeId,
currentGameId,
);
}
if (data && data.status !== 0) {
if (
data?.status === 12 ||
(data?.message &&
data.message.includes(
'non-root place',
))
) {
showLoadingOverlayResult(
data.message ||
(await t(
'revertLogo.nonRootPlaceRestrictions',
)),
{
text: await t(
'revertLogo.close',
),
onClick: () =>
closeInterface(true),
},
);
return;
}
if (data?.joinScript) {
joinApiResponse = data;
break;
}
}
} catch (innerErr) {
console.error(
'Join API attempt failed:',
innerErr,
);
}
if (!joinApiResponse && retries < MAX_RETRIES) {
await new Promise((r) => setTimeout(r, 2000));
}
}
if (joinApiResponse?.joinScript?.GameId) {
currentGameId = joinApiResponse.joinScript.GameId;
}
} catch (e) {
console.error('Error in server info fetch loop:', e);
}
}
if (!document.body.classList.contains(HIDE_ROBLOX_UI_CLASS)) {
return;
}
try {
const joinScript = joinApiResponse?.joinScript;
let regionCode, regionName, ownerInfo;
if (joinScript) {
const resolvedGameId =
joinScript.GameId || currentGameId;
if (joinScript.PrivateServerOwnerID) {
try {
const ownerId = joinScript.PrivateServerOwnerID;
const [uData, thumbMap] = await Promise.all([
callRobloxApi({
subdomain: 'users',
endpoint: '/v1/users',
method: 'POST',
body: { userIds: [ownerId] },
}).then((r) => r.json()),
fetchThumbnails(
[{ id: ownerId }],
'AvatarHeadshot',
'48x48',
false,
),
]);
const thumbData = thumbMap.get(ownerId);
if (uData?.data?.[0]) {
ownerInfo = {
id: uData.data[0].id,
displayName: uData.data[0].displayName,
thumbnailUrl:
thumbData?.imageUrl || null,
};
}
} catch {}
}
regionCode = joinApiResponse.country;
regionName = joinApiResponse.region;
if (!regionCode || !regionName) {
const dataCenterId = joinScript.DataCenterId;
if (dataCenterId && serverIpMap[dataCenterId]) {
const loc = serverIpMap[dataCenterId];
regionCode = loc.country;
regionName = loc.region
? `${loc.city}, ${loc.region}`
: loc.city;
}
}
if (resolvedGameId) {
await fetchServerDetails(placeId, [resolvedGameId]);
}
const htmlDetails = buildInfoList(
resolvedGameId,
isPrivateServer,
regionCode,
regionName,
interceptedServerData,
joinScript.PlaceVersion,
joinScript.ChannelName,
joinScript.RccVersion,
ownerInfo,
);
const gameDetails = await gameDetailsPromise;
updateServerInfo(
gameDetails.name,
gameDetails.iconUrl,
htmlDetails,
);
attachLiveUptimeListener();
updateLoadingOverlayText(
await t('revertLogo.joiningServer'),
);
} else {
if (currentGameId) {
await fetchServerDetails(placeId, [currentGameId]);
}
const htmlDetails = buildInfoList(
currentGameId,
isPrivateServer,
null,
null,
interceptedServerData,
null,
null,
null,
null,
);
const details = await gameDetailsPromise;
updateServerInfo(
details.name,
details.iconUrl,
htmlDetails,
);
attachLiveUptimeListener();
updateLoadingOverlayText(
await t('revertLogo.waitingForRoblox'),
);
}
pollClientStatus(placeId);
} catch (e) {
console.error('Rendering error:', e);
const details = await gameDetailsPromise;
updateServerInfo(details.name, details.iconUrl, null);
updateLoadingOverlayText(await t('revertLogo.launching'));
pollClientStatus(placeId);
}
};
if (!settings.whatamIJoiningEnabled) return;
observeElement('#gamelaunch', processGameLaunchData, {
observeAttributes: true,
onRemove: () => {
gameLaunchElementExists = false;
},
});
},
);
}
function initialize() {
try {
initRevertLogo();
initializeJoinDialogEnhancer();
} catch {}
}
export function init() {
closeInterface(true);
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize, {
once: true,
});
} else {
initialize();
}
}