-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy path40method.js
More file actions
2941 lines (2637 loc) · 117 KB
/
Copy path40method.js
File metadata and controls
2941 lines (2637 loc) · 117 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
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
import { observeElement } from '../../core/observer.js';
import { callRobloxApiJson, callRobloxApi } from '../../core/api.js';
import { getItemDetails } from '../../core/catalog/itemPrice.js';
import { getUserCurrency } from '../../core/user/userCurrency.js';
import {
launchMultiplayerGame,
launchStudioForGame,
} from '../../core/utils/launcher.js';
import { createOverlay } from '../../core/ui/overlay.js';
import { createDropdown } from '../../core/ui/dropdown.js';
import { createSpinner } from '../../core/ui/spinner.js';
import { createStyledInput } from '../../core/ui/catalog/input.js';
import { fetchThumbnails } from '../../core/thumbnail/thumbnails.js';
import DOMPurify from 'dompurify';
import { getPlaceIdFromUrl } from '../../core/idExtractor.js';
import { cleanPrice } from '../../core/utils/priceCleaner.js';
const ROVALRA_PLACE_ID = '107845747621646';
let assetToSubcategoryMap = null;
let classicClothingSubcategories = null;
let metadataPromise = null;
const ROVALRA_TEMPLATE_ASSET_ID = 107845747621646;
const GAMEPASS_DISABLE_DATE = new Date(2026, 4, 29).getTime();
const isGamePassBeforeDisable = () => {
return Date.now() < GAMEPASS_DISABLE_DATE;
};
const isGamePassDisabled = () => {
return Date.now() >= GAMEPASS_DISABLE_DATE;
};
async function fetchTemplateBlobViaBatch() {
const batchResponse = await callRobloxApi({
subdomain: 'assetdelivery',
endpoint: '/v2/assets/batch',
method: 'POST',
body: [
{
requestId: 'rovalra_req_' + Date.now(),
assetId: ROVALRA_TEMPLATE_ASSET_ID,
type: 'Place',
format: 'rbxl',
},
],
});
if (!batchResponse.ok) {
throw new Error(`Batch API failed: ${batchResponse.status}`);
}
const batchData = await batchResponse.json();
if (
!batchData ||
!batchData[0] ||
!batchData[0].locations ||
!batchData[0].locations[0]
) {
throw new Error(
'Could not retrieve template download location from Batch API',
);
}
const cdnUrl = batchData[0].locations[0].location;
const fileResponse = await callRobloxApi({
fullUrl: cdnUrl,
method: 'GET',
credentials: 'omit',
});
if (!fileResponse.ok) {
throw new Error('Failed to download file from CDN');
}
return await fileResponse.blob();
}
async function publishTemplateToPlace(targetPlaceId) {
try {
const fileBlob = await fetchTemplateBlobViaBatch();
const formData = new FormData();
const requestData = {
assetType: 'Place',
assetId: parseInt(targetPlaceId),
published: true,
creationContext: {},
};
formData.append('request', JSON.stringify(requestData));
formData.append('fileContent', fileBlob, 'place.rbxl');
const response = await callRobloxApi({
subdomain: 'apis',
endpoint: `/assets/user-auth/v1/assets/${targetPlaceId}`,
method: 'PATCH',
body: formData,
});
if (!response.ok) {
const txt = await response.text();
throw new Error(`Patch upload failed: ${response.status} ${txt}`);
}
return true;
} catch (error) {
console.error('RoValra: Auto-publish failed', error);
throw error;
}
}
async function fetchCatalogMetadata() {
if (assetToSubcategoryMap && classicClothingSubcategories) return;
if (metadataPromise) return metadataPromise;
metadataPromise = (async () => {
try {
const [assetToSubResponse, subcategoriesResponse] =
await Promise.all([
callRobloxApiJson({
subdomain: 'catalog',
endpoint: '/v1/asset-to-subcategory',
method: 'GET',
}),
callRobloxApiJson({
subdomain: 'catalog',
endpoint: '/v1/subcategories',
method: 'GET',
}),
]);
assetToSubcategoryMap = assetToSubResponse;
const classicKeys = [
'ClassicShirts',
'ClassicPants',
'ClassicTShirts',
];
classicClothingSubcategories = [];
if (subcategoriesResponse) {
for (const key of classicKeys) {
if (subcategoriesResponse[key] !== undefined) {
classicClothingSubcategories.push(
subcategoriesResponse[key],
);
}
}
}
} catch (error) {
console.warn('RoValra: Failed to fetch catalog metadata', error);
} finally {
metadataPromise = null;
}
})();
return metadataPromise;
}
async function fetchGamesForGroup(groupId) {
let allGames = [];
let nextCursor = null;
do {
const url =
`/universes/v1/search?CreatorType=Group&CreatorTargetId=${groupId}&IsArchived=false&Surface=CreatorHubCreations&PageSize=100&SortParam=LastUpdated&SortOrder=Desc` +
(nextCursor ? `&cursor=${nextCursor}` : '');
const response = await callRobloxApiJson({
subdomain: 'apis',
endpoint: url,
});
if (response.data) {
allGames = allGames.concat(response.data);
}
nextCursor = response.nextPageCursor;
} while (nextCursor);
return allGames;
}
async function updateGameDescription(universeId, sourcePlaceId) {
try {
const versionResponse = await callRobloxApiJson({
subdomain: 'develop',
endpoint: '/v1/assets/latest-versions',
method: 'POST',
body: {
assetIds: [parseInt(sourcePlaceId)],
versionStatus: 'Published',
},
});
let versionNumber = 'Unknown';
if (
versionResponse &&
versionResponse.results &&
versionResponse.results.length > 0
) {
versionNumber = versionResponse.results[0].versionNumber;
}
const configResponse = await callRobloxApiJson({
subdomain: 'develop',
endpoint: `/v1/universes/${universeId}/configuration`,
method: 'GET',
});
if (!configResponse) return;
const newDescription = `SourcePlaceId: ${sourcePlaceId} Version: ${versionNumber}`;
const patchBody = {
name: configResponse.name,
description: newDescription,
isFriendsOnly: configResponse.isFriendsOnly,
studioAccessToApisAllowed:
configResponse.isStudioAccessToApisAllowed,
};
await callRobloxApiJson({
subdomain: 'develop',
endpoint: `/v2/universes/${universeId}/configuration`,
method: 'PATCH',
body: patchBody,
});
} catch (e) {
console.warn('RoValra: Failed to update game description', e);
}
}
async function validateGameSync(universeId, placeId) {
try {
const versionResponse = await callRobloxApiJson({
subdomain: 'develop',
endpoint: '/v1/assets/latest-versions',
method: 'POST',
body: {
assetIds: [parseInt(ROVALRA_PLACE_ID)],
versionStatus: 'Published',
},
});
let latestVersion = 0;
if (
versionResponse &&
versionResponse.results &&
versionResponse.results.length > 0
) {
latestVersion = versionResponse.results[0].versionNumber;
}
let description = '';
if (placeId) {
const gameDetails = await callRobloxApiJson({
subdomain: 'games',
endpoint: `/v1/games/multiget-place-details?placeIds=${placeId}`,
method: 'GET',
});
if (gameDetails && gameDetails.length > 0) {
description = gameDetails[0].description || '';
}
} else {
const configResponse = await callRobloxApiJson({
subdomain: 'develop',
endpoint: `/v1/universes/${universeId}/configuration`,
method: 'GET',
});
if (configResponse) description = configResponse.description || '';
}
const match = description.match(
/SourcePlaceId:\s*(\d+)\s*Version:\s*(\d+)/,
);
if (!match) return { valid: false, reason: 'missing_metadata' };
const sourceId = match[1];
const currentVersion = parseInt(match[2], 10);
if (sourceId !== ROVALRA_PLACE_ID || currentVersion < latestVersion) {
return {
valid: false,
reason: 'outdated',
current: currentVersion,
latest: latestVersion,
};
}
return { valid: true };
} catch (e) {
return { valid: true };
}
}
const getCurrentUserId = () => {
const meta = document.querySelector('meta[name="user-data"]');
return meta ? meta.getAttribute('data-userid') : null;
};
const getCartItems = () => {
const cartModal = document.querySelector('.shopping-cart-modal');
if (!cartModal) return [];
const cartItems = [];
const itemContainers = cartModal.querySelectorAll('.cart-item-container');
itemContainers.forEach((container) => {
const link = container.querySelector(
'.item-details-container a.item-name',
);
const priceText = container.querySelector('.item-price .price-text');
if (link && priceText) {
const href = link.getAttribute('href');
const match = href.match(
/\/(?:[a-z]{2}(?:-[a-z]{2})?\/)?(catalog|bundles)\/(\d+)/i,
);
if (match) {
const type =
match[1].toLowerCase() === 'bundles' ? 'Bundle' : 'Asset';
cartItems.push({
id: match[2],
name: link.textContent.trim(),
price: cleanPrice(priceText.textContent),
type: type,
thumbnail: null,
});
}
}
});
return cartItems;
};
const getBatchPurchaseItems = (modal) => {
const thumbnails = modal.querySelectorAll(
'.modal-multi-item-image-container img',
);
const items = [];
thumbnails.forEach((img) => {
const alt = img.getAttribute('alt');
if (alt) {
items.push({
name: alt.trim(),
});
}
});
return items;
};
const validateCartMatch = (modalItems, cartItems) => {
if (modalItems.length !== cartItems.length) return false;
const modalNames = new Set(modalItems.map((item) => item.name));
const cartNames = new Set(cartItems.map((item) => item.name));
for (const name of modalNames) {
if (!cartNames.has(name)) return false;
}
return true;
};
const checkItemOwnership = async (userId, itemId, itemType) => {
try {
const typeMap = {
Asset: 'Asset',
Bundle: 'Bundle',
GamePass: 'GamePass',
};
const type = typeMap[itemType] || 'Asset';
const response = await callRobloxApi({
subdomain: 'inventory',
endpoint: `/v1/users/${userId}/items/${type}/${itemId}`,
method: 'GET',
});
if (response.ok) {
const data = await response.json();
return data && data.data && data.data.length > 0;
}
return false;
} catch (error) {
console.warn('RoValra: Could not check item ownership:', error);
return false;
}
};
const getUniverseId = () => {
const meta = document.getElementById('game-detail-meta-data');
return meta ? meta.getAttribute('data-universe-id') : null;
};
async function fetchGamePassesForUniverse(universeId) {
let gamePasses = [];
let cursor = '';
const limit = 50;
try {
do {
const url =
`/game-passes/v1/universes/${universeId}/game-passes?pageSize=${limit}&passView=Full` +
(cursor ? `&cursor=${cursor}` : '');
const response = await callRobloxApiJson({
subdomain: 'apis',
endpoint: url,
method: 'GET',
});
if (response.gamePasses) {
gamePasses = gamePasses.concat(response.gamePasses);
}
cursor = response.nextPageToken;
} while (cursor);
} catch (error) {
console.warn('RoValra: Failed to fetch game passes via API', error);
}
return gamePasses;
}
let lastBuyButtonClickTime = 0;
const detectAndAddSaveButton = () => {
document.addEventListener(
'click',
(e) => {
if (e.target.closest('.shopping-cart-buy-button')) {
lastBuyButtonClickTime = Date.now();
}
},
{ capture: true, passive: true },
);
observeElement(
'.modal-content, .unified-purchase-dialog-content, .modal-dialog',
(element) => {
const modal = element.classList.contains('modal-dialog')
? element.querySelector('.modal-content')
: element;
if (!modal) return;
if (modal.classList.contains('unified-purchase-dialog-content')) {
const wasTriggeredByButton =
Date.now() - lastBuyButtonClickTime < 2000;
const hasBuyButton = modal.querySelector(
'[data-testid="purchase-confirm-button"]',
);
if (!wasTriggeredByButton && !hasBuyButton) {
return;
}
}
modal.addEventListener('rovalraPurchasePromptReady', () => {
addSaveButton(modal);
});
if (modal.getAttribute('data-rovalra-item-processed') === 'true') {
addSaveButton(modal);
}
},
{
multiple: true,
},
);
};
export const createAndShowPopup = (onSave, initialState = null) => {
const currentUserId = getCurrentUserId();
if (!currentUserId) {
alert(
'Could not identify your user ID. Please make sure you are logged in.',
);
return;
}
const bodyContent = document.createElement('div');
bodyContent.innerHTML = DOMPurify.sanitize(
`
<div id="sr-view-main">
<h4 class="text font-header-2" style="margin:0 0 12px 0;">Set Up an Experience</h4>
<p class="text font-body" style="margin: 0 0 10px 0; line-height:1.4;">
<strong>Only a specific template works</strong>
</p>
<p class="text font-body" style="margin: 0 0 8px 0;">Select a group you can manage experiences in. <br>And the extension will create the experience for you.</p>
<div id="sr-group-dropdown-container" style="margin-bottom: 16px;"></div>
<div style="display:flex;align-items:center;gap:8px;margin:12px 0 8px 0;">
<hr style="flex:1;border:none;border-top:1px solid rgba(255,255,255,0.15);" />
<span class="text font-body" style="font-size:12px;opacity:.7;">OR</span>
<hr style="flex:1;border:none;border-top:1px solid rgba(255,255,255,0.15);" />
</div>
<p class="text font-body" style="margin: 0 0 8px 0;">Manually enter a Place ID <br> (Only do this if you know what your doing.)</p>
<div id="sr-game-id-input-container" style="width: 100%;"></div>
<div style="display:flex;align-items:center;gap:8px;margin:12px 0 8px 0;">
<hr style="flex:1;border:none;border-top:1px solid rgba(255,255,255,0.15);" />
<span class="text font-body" style="font-size:12px;opacity:.7;">OR</span>
<hr style="flex:1;border:none;border-top:1px solid rgba(255,255,255,0.15);" />
</div>
<button id="sr-use-rovalra-group-btn" class="btn-secondary-md btn-min-width" style="width: 100%;">Donate Saved Robux to RoValra</button>
<p class="text font-body" style="margin:12px 0 0 0;font-size:12px;opacity:.65;">Estimated savings shown later are approximate and may be inaccurate.</p>
</div>
<div id="sr-view-non-owner-ack" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Important Information</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>Owner Account:</strong> The group owner CANNOT be the same account you are buying items with. The owner should be a secured alt account with 2FA enabled and a strong, unique password.</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>Payouts:</strong> Only the group's owner account can pay out the saved Robux from the group's funds.</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>Pending Robux:</strong> Be aware that after using this feature, the Robux will be pending for approximately one month before they can be paid out.</p>
<button class="btn-cta-md btn-min-width" id="sr-acknowledge-btn" style="width: 100%; margin-top: 10px;">I Acknowledge</button>
</div>
<div id="sr-view-no-group-info" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Group Required</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;">To use the 40% method with your own group, you need a group that you can manage experiences in.</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>Important:</strong> For this to work correctly, the group must be owned by a secure alternate account. Your main account (the one you're using to buy items) should have a role with permissions to create and manage group experiences.</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;">If you don't have a suitable group, you can instead support RoValra by using our experience to process the purchase, which will give RoValra the saved Robux ❤️</p>
<div style="display: flex; gap: 8px; margin-top: 16px;">
<button class="btn-secondary-md btn-min-width" id="sr-no-group-back-btn" style="flex: 1;">Go Back</button>
</div>
</div>
<div id="sr-view-owner-warning" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Ownership Detected</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;">The 40% method will not work if you are the owner of this group. Please select a different group or transfer ownership to a secured alt account.</p>
<div style="display: flex; gap: 8px; margin-top: 16px;">
<button class="btn-secondary-md btn-min-width" id="sr-owner-warning-back-btn" style="flex: 1;">Go Back</button>
</div>
</div>
<div id="sr-view-manual-ack" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Experience Accepted</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height:1.5;">
<strong>Only specific experiences work.</strong> Ensure this experience is set up with the required scripts to handle in-game purchases.
</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height:1.5;">
Make sure the experience belongs to a group <strong>you control, but is not owned by this account</strong>. Preferably the group should be owned by an alt. If you own the group, the 40% method will not work.
</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height:1.5;">
The saved Robux will be pending for roughly one month before payout. Use a secure alt as group owner for payouts.
</p>
<button id="sr-manual-ack-btn" class="btn-cta-md btn-min-width" style="width:100%;">I Understand & Continue</button>
</div>
<div id="sr-view-wip" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Create Experience</h4>
<p class="text font-body" style="margin: 5px 0 16px 0; line-height: 1.5;">Create a new experience for this group to use the 40% method.</p>
<div id="sr-create-game-error" class="text font-body" style="margin-bottom: 10px; font-size: 12px; color: #d32f2f; display: none;"></div>
<button class="btn-cta-md btn-min-width" id="sr-create-new-game-btn" style="width: 100%;">Create New Experience</button>
</div>
<div id="sr-view-manual-create-instructions" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Create New Experience</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;">To create a new experience for this method:</p>
<div style="margin-bottom: 16px; border-radius: 8px; overflow: hidden;">
<iframe width="100%" height="250" src="https://www.youtube.com/embed/-kUAWWmmkaQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>
<ol class="text font-body" style="margin: 0 0 16px 0; padding-left: 20px; line-height: 1.5;">
<li>Open the uncopylocked experience in Studio: <a href="#" id="sr-edit-game-link" style="text-decoration: underline;">Open Studio</a></li>
<li>In Studio, go to <strong>File > Game Settings > Security > Turn on "Allow Third Party Sales" > File > Publish to Roblox As...</strong></li>
<li>Select this group from the Creator list.</li>
<li>Click <strong>Create</strong> and the experience will be published</li>
</ol>
<p class="text font-body" style="margin: 0 0 16px 0; line-height: 1.5;">Once published, click the button below and we'll automatically find and select it for you.</p>
<div style="display: flex; gap: 8px; margin-top: 16px;">
<button class="btn-secondary-md btn-min-width" id="sr-manual-create-back-btn" style="flex: 1;">Back</button>
<button class="btn-cta-md btn-min-width" id="sr-manual-create-done-btn" style="flex: 1;">I've Published the Game</button>
</div>
</div>
<div id="sr-view-finding-game" class="sr-hidden">
<div style="text-align: center; padding: 20px 0;">
<div id="sr-finding-game-spinner" style="margin: 0 auto 16px;"></div>
<h4 class="text font-header-2" style="margin: 0 0 8px 0;">Finding Your Experience</h4>
<p class="text font-body" style="margin: 0;">Please wait while we look for your newly published experience...</p>
</div>
</div>
<div id="sr-view-rovalra-group" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Donate to RoValra</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>How it works:</strong> Your purchase will go through a game owned by RoValra, and RoValra will earn a commission on your purchase which will help support RoValra's development.</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>No Setup Required:</strong> Perfect if you don't have your own group or want to support the extension!</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;"><strong>Requirements:</strong></p>
<ul class="text font-body" style="margin: 0 0 10px 0; padding-left: 20px; line-height: 1.5;">
<li>The saved Robux will go to RoValra to help fund development</li>
<li>You still get the item you're purchasing</li>
<li>And you will support RoValra at no extra cost for you.</li>
</ul>
<div style="display: flex; gap: 8px; margin-top: 16px;">
<button class="btn-secondary-md btn-min-width" id="sr-rovalra-back-btn" style="flex: 1;">Back</button>
<button class="btn-cta-md btn-min-width" id="sr-rovalra-confirm-btn" style="flex: 1;">I Understand & Continue</button>
</div>
</div>
<div id="sr-view-validation-warning" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Validation Warning</h4>
<div id="sr-validation-message-container"></div>
<div style="display: flex; flex-direction: column; gap: 8px; margin-top: 16px;">
<button class="btn-cta-md btn-min-width" id="sr-validation-create-btn" style="display: none;">Create New Experience</button>
<button class="btn-cta-md btn-min-width" id="sr-validation-update-btn" style="display: none;">Update Experience</button>
<button class="btn-secondary-md btn-min-width" id="sr-validation-use-anyway-btn">Use Anyway</button>
</div>
</div>
<div id="sr-view-permission-error" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Permission Required</h4>
<p class="text font-body" style="margin: 5px 0 12px 0; line-height: 1.5;">You don't have permission to manage experiences for this group. You need a role with creation/management rights. You can pick a different group or choose the donate option instead.</p>
<div style="display: flex; gap: 8px;">
<button class="btn-secondary-md btn-min-width" id="sr-permission-error-back-btn" style="flex: 1;">Back to Group Selection</button>
</div>
</div>
<div id="sr-view-update-instructions" class="sr-hidden">
<h4 class="text font-header-2" style="margin: 0 0 10px 0;">Update Experience</h4>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;">
Experience: <strong id="sr-update-game-name">Loading...</strong>
</p>
<p class="text font-body" style="margin: 5px 0 10px 0; line-height: 1.5;">Your experience is outdated. To ensure it works correctly, please update it.</p>
<div style="background-color: rgba(211, 47, 47, 0.1); border: 1px solid rgba(211, 47, 47, 0.3); border-radius: 8px; padding: 12px; margin-bottom: 16px;">
<p class="text font-body" style="margin: 0 0 8px 0; font-weight: 600; color: #d32f2f;">⚠️ WARNING: This will overwrite your game!</p>
<p class="text font-body" style="margin: 0; font-size: 14px;">Updating will replace the entire experience with the latest 40% method template. Any existing work in this place will be overwritten.</p>
</div>
<div style="margin-bottom: 16px;">
<label style="display: flex; align-items: center; gap: 8px; cursor: pointer;">
<input type="checkbox" id="sr-update-agree-checkbox" style="width: 16px; height: 16px;">
<span class="text font-body" style="font-size: 14px;">I agree to overwrite this experience</span>
</label>
</div>
<div style="display: flex; gap: 8px; margin-top: 16px;">
<button class="btn-secondary-md btn-min-width" id="sr-update-use-anyway-btn" style="flex: 1;">Use Anyway</button>
<button class="btn-cta-md btn-min-width" id="sr-update-confirm-btn" style="flex: 1;" disabled>Update Now</button>
</div>
</div>
`,
{
ADD_ATTR: ['target', 'allow', 'allowfullscreen', 'frameborder'],
ADD_TAGS: ['iframe'],
},
);
const saveBtn = document.createElement('button');
saveBtn.textContent = 'Save & Continue';
saveBtn.className = 'btn-cta-md btn-min-width';
saveBtn.id = 'sr-save-btn';
const { overlay, close } = createOverlay({
title: 'Set Up Your Game',
bodyContent: bodyContent,
actions: [saveBtn],
maxWidth: '500px',
showLogo: true,
});
overlay.addEventListener(
'click',
(e) => {
if (e.target === overlay) {
e.stopPropagation();
e.stopImmediatePropagation();
}
},
true,
);
const style = document.createElement('style');
style.textContent = '.sr-hidden { display: none !important; }';
document.head.appendChild(style);
const gameIdInputContainer = bodyContent.querySelector(
'#sr-game-id-input-container',
);
const { container: gameIdInputWrapper, input: gameIdInput } =
createStyledInput({
id: 'sr-game-id-input',
label: 'Place ID',
placeholder: ' ',
});
gameIdInputContainer.appendChild(gameIdInputWrapper);
const gameIdErrorEl = document.createElement('div');
gameIdErrorEl.id = 'sr-game-id-error';
gameIdErrorEl.className = 'text font-body';
gameIdErrorEl.style.cssText =
'margin-top:6px;font-size:12px;color:#d32f2f;display:none;';
gameIdInputContainer.appendChild(gameIdErrorEl);
const findingGameSpinner = bodyContent.querySelector(
'#sr-finding-game-spinner',
);
if (findingGameSpinner) {
findingGameSpinner.appendChild(
createSpinner({ size: '48px', color: 'currentColor' }),
);
}
const groupDropdownContainer = bodyContent.querySelector(
'#sr-group-dropdown-container',
);
const viewMain = bodyContent.querySelector('#sr-view-main');
const viewNonOwnerAck = bodyContent.querySelector('#sr-view-non-owner-ack');
const viewNoGroupInfo = bodyContent.querySelector('#sr-view-no-group-info');
const noGroupBackBtn = bodyContent.querySelector('#sr-no-group-back-btn');
const viewOwnerWarning = bodyContent.querySelector(
'#sr-view-owner-warning',
);
const ownerWarningBackBtn = bodyContent.querySelector(
'#sr-owner-warning-back-btn',
);
const viewWIP = bodyContent.querySelector('#sr-view-wip');
const viewManualCreateInstructions = bodyContent.querySelector(
'#sr-view-manual-create-instructions',
);
const viewFindingGame = bodyContent.querySelector('#sr-view-finding-game');
const viewRoValraGroup = bodyContent.querySelector(
'#sr-view-rovalra-group',
);
const viewPermissionError = bodyContent.querySelector(
'#sr-view-permission-error',
);
const viewValidationWarning = bodyContent.querySelector(
'#sr-view-validation-warning',
);
const viewUpdateInstructions = bodyContent.querySelector(
'#sr-view-update-instructions',
);
const updateUseAnywayBtn = bodyContent.querySelector(
'#sr-update-use-anyway-btn',
);
const updateGameNameEl = bodyContent.querySelector('#sr-update-game-name');
const updateConfirmBtn = bodyContent.querySelector(
'#sr-update-confirm-btn',
);
const updateAgreeCheckbox = bodyContent.querySelector(
'#sr-update-agree-checkbox',
);
const validationUseAnywayBtn = bodyContent.querySelector(
'#sr-validation-use-anyway-btn',
);
const validationCreateBtn = bodyContent.querySelector(
'#sr-validation-create-btn',
);
const validationUpdateBtn = bodyContent.querySelector(
'#sr-validation-update-btn',
);
const permissionErrorBackBtn = bodyContent.querySelector(
'#sr-permission-error-back-btn',
);
const acknowledgeBtn = bodyContent.querySelector('#sr-acknowledge-btn');
const useRoValraGroupBtn = bodyContent.querySelector(
'#sr-use-rovalra-group-btn',
);
const rovalraBackBtn = bodyContent.querySelector('#sr-rovalra-back-btn');
const rovalraConfirmBtn = bodyContent.querySelector(
'#sr-rovalra-confirm-btn',
);
const createNewGameBtn = bodyContent.querySelector(
'#sr-create-new-game-btn',
);
const manualAckView = bodyContent.querySelector('#sr-view-manual-ack');
const manualAckBtn = bodyContent.querySelector('#sr-manual-ack-btn');
const manualCreateBackBtn = bodyContent.querySelector(
'#sr-manual-create-back-btn',
);
const manualCreateDoneBtn = bodyContent.querySelector(
'#sr-manual-create-done-btn',
);
const notFoundBackBtn = bodyContent.querySelector('#sr-not-found-back-btn');
const notFoundRetryBtn = bodyContent.querySelector(
'#sr-not-found-retry-btn',
);
const editGameLink = bodyContent.querySelector('#sr-edit-game-link');
let manualPlaceIdCandidate = null;
let manualUniverseIdCandidate = null;
let lastValidationReason = null;
let initialUserPlaceVersion = 0;
const safeSaveSettings = (placeId, useGroup, onSuccess) => {
if (
typeof chrome !== 'undefined' &&
chrome.storage &&
chrome.storage.local
) {
chrome.storage.local.set(
{
RobuxPlaceId: placeId,
useRoValraGroup: useGroup,
},
() => {
if (chrome.runtime.lastError) {
console.error(
'RoValra: Storage save error:',
chrome.runtime.lastError,
);
alert(
'Failed to save settings: ' +
chrome.runtime.lastError.message,
);
} else {
if (onSuccess) onSuccess();
}
},
);
} else {
console.error('RoValra: Storage API unavailable.');
alert('Failed to save settings. Storage API unavailable.');
}
};
if (noGroupBackBtn) {
noGroupBackBtn.addEventListener('click', () => {
viewNoGroupInfo.classList.add('sr-hidden');
viewMain.classList.remove('sr-hidden');
saveBtn.style.display = '';
if (groupDropdown && groupDropdown.element) {
const selectEl = groupDropdown.element.querySelector('select');
if (selectEl) selectEl.value = '';
}
});
}
let groupDropdown = null;
let selectedGroupId = null;
let initialGroupGames = [];
const showValidationWarning = async (
reason,
placeId,
universeId,
gameName = null,
) => {
lastValidationReason = reason;
if (gameName && updateGameNameEl)
updateGameNameEl.textContent = gameName;
const container = bodyContent.querySelector(
'#sr-validation-message-container',
);
validationUpdateBtn.style.display = 'none';
validationCreateBtn.style.display = 'none';
if (reason === 'missing_metadata' || reason === 'wrong_source') {
container.innerHTML = DOMPurify.sanitize(`
<p class="text font-body" style="margin-bottom: 10px;">This experience does not appear to support the 40% method (missing or invalid metadata).</p>
<p class="text font-body" style="margin-bottom: 10px;">You can update the experience to fix this, or create a new one.</p>
`);
validationCreateBtn.style.display = 'block';
validationUpdateBtn.style.display = 'block';
} else if (reason === 'outdated') {
container.innerHTML = DOMPurify.sanitize(`
<p class="text font-body" style="margin-bottom: 10px;">Your game version is out of sync with the latest template.</p>
<p class="text font-body" style="margin-bottom: 10px;">Please update your game to avoid issues with purchases.</p>
`);
validationUpdateBtn.style.display = 'block';
} else {
container.innerHTML =
'<p class="text font-body">Validation failed. Please check your game settings.</p>';
}
manualPlaceIdCandidate = placeId;
manualUniverseIdCandidate = universeId;
viewMain.classList.add('sr-hidden');
saveBtn.style.display = 'none';
if (reason === 'outdated') {
try {
const vResp = await callRobloxApiJson({
subdomain: 'develop',
endpoint: '/v1/assets/latest-versions',
method: 'POST',
body: { assetIds: [placeId], versionStatus: 'Published' },
});
if (vResp && vResp.results && vResp.results.length > 0) {
initialUserPlaceVersion = vResp.results[0].versionNumber;
}
} catch (e) {
console.error(
'RoValra: Failed to fetch initial place version',
e,
);
}
viewUpdateInstructions.classList.remove('sr-hidden');
return;
}
viewValidationWarning.classList.remove('sr-hidden');
};
const handleGroupSelection = async (groupId) => {
if (!groupId) return;
if (groupId === 'no-group') {
viewMain.classList.add('sr-hidden');
saveBtn.style.display = 'none';
viewNoGroupInfo.classList.remove('sr-hidden');
return;
}
selectedGroupId = groupId;
viewMain.classList.add('sr-hidden');
saveBtn.style.display = 'none';
try {
const data = await callRobloxApiJson({
subdomain: 'groups',
endpoint: `/v1/groups/${groupId}`,
});
if (data.owner && String(data.owner.userId) === currentUserId) {
viewOwnerWarning.classList.remove('sr-hidden');
} else {
viewNonOwnerAck.classList.remove('sr-hidden');
}
} catch (error) {
console.error('Failed to fetch group details:', error);
close();
alert('Could not check group ownership. Please try again.');
}
};
const loadGroups = async () => {
try {
const data = await callRobloxApiJson({
subdomain: 'apis',
endpoint: '/creator-home-api/v1/groups',
});
const groupItems = [
{ value: '', label: '-- Please choose a group --' },
...data.groups.map((group) => ({
value: String(group.id),
label: group.name,
})),
];
groupItems.push({
value: 'no-group',
label: "I don't have a group",
});
groupDropdown = createDropdown({
items: groupItems,
initialValue: '',
onValueChange: handleGroupSelection,
showFlags: false,
});
groupDropdownContainer.appendChild(groupDropdown.element);
try {
groupDropdown.element.style.width = '100%';
const selectEl = groupDropdown.element.querySelector('select');
if (selectEl) {
selectEl.style.height = '40px';
selectEl.style.borderRadius = '8px';
selectEl.style.padding = '0 14px';
selectEl.style.boxSizing = 'border-box';
selectEl.style.width = '100%';
}
} catch {}
} catch (error) {
console.error('RoValra: Failed to fetch groups:', error);
groupDropdownContainer.innerHTML = DOMPurify.sanitize(
'<div class="text font-body" style="color: var(--rovalra-secondary-text-color);">Failed to load groups. Please refresh and try again.</div>',
);
}
};
acknowledgeBtn.addEventListener('click', () => {
if (manualPlaceIdCandidate !== null) {
const placeIdToSave = manualPlaceIdCandidate;
manualPlaceIdCandidate = null;
viewNonOwnerAck.classList.add('sr-hidden');
safeSaveSettings(placeIdToSave, false, async () => {
close();
await showInitialConfirmation(placeIdToSave, false);
onSave();
});
} else {
viewNonOwnerAck.classList.add('sr-hidden');
viewWIP.classList.remove('sr-hidden');
}
});
manualAckBtn.addEventListener('click', () => {
manualAckView.classList.add('sr-hidden');
if (manualPlaceIdCandidate !== null) {
const placeIdToSave = manualPlaceIdCandidate;
manualPlaceIdCandidate = null;
safeSaveSettings(placeIdToSave, false, async () => {
close();
await showInitialConfirmation(placeIdToSave, false);
onSave();
});
}