-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
scm.js
1149 lines (1005 loc) · 39.7 KB
/
scm.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
function Init(friendMessage, checkBlocked, debug) {
const APP_VERSION = 31;
const APP_NAME = "Social Club Utility Tool";
const APP_NAME_SHORT = "SCUT";
const APP_AUTHOR = "Senex";
const APP_LINK = "https://github.com/Senexis/Social-Club-Tool";
const APP_LINK_ISSUES = "https://github.com/Senexis/Social-Club-Tool/issues/new";
const APP_LINK_SC = "https://" + window.location.host;
const APP_CLIENT_VERSION = localStorage.getItem('SCUT_CLIENT_VERSION');
const APP_REQUEST_DELAY = 1000;
try {
console.log.apply(console, ["%c " + APP_NAME + " %cv" + APP_VERSION + " by " + APP_AUTHOR + " %c " + APP_LINK, "background:#000000;color:#f90", "background:#000000;color:#ffffff", ""]);
} catch (error) {
console.log(APP_NAME + " v" + APP_VERSION + " by " + APP_AUTHOR + " - " + APP_LINK);
}
if (friendMessage === undefined) friendMessage = "";
friendMessage = friendMessage.replace(/\\\"/g, '').replace(/\"/g, '').replace(/\s\s+/g, ' ').trim();
if (checkBlocked === undefined) checkBlocked = 1;
if (debug === undefined) debug = 0;
if (debug === 1) alert(APP_NAME + " v" + APP_VERSION + " started in debug mode. If you see this and don't want to, remove the last 1 from Init().");
// Generic helper functions.
function GetCookie(name) {
var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
return v ? v[2] : null;
}
// UI utility functions.
function LogInfo(title, body) {
console.groupCollapsed("[" + APP_NAME_SHORT + ": INFO] " + title);
console.log(body);
console.groupEnd();
}
function LogError(title, body) {
console.groupCollapsed("[" + APP_NAME_SHORT + ": ERROR] " + title);
console.error(body);
console.groupEnd();
}
function LogRequest(title, request, response) {
console.groupCollapsed("[" + APP_NAME_SHORT + ": AJAX] " + title);
console.group("Request");
console.log(request);
console.groupEnd();
console.group("Response");
console.log(response);
console.groupEnd();
console.groupEnd();
}
function GetYesNoSwalArgs(type, title, body) {
return {
type: type,
title: title,
text: body,
allowEscapeKey: false,
cancelButtonText: "No",
closeOnConfirm: false,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
html: true,
showCancelButton: true,
showLoaderOnConfirm: true
};
}
function GetTimedSwalArgs(type, title, body, timer) {
if (type === "success") timer = 5000;
if (type === "error") timer = 60000;
if (timer === undefined) timer = 5000;
return {
type: type,
title: title,
text: body,
allowOutsideClick: true,
html: true,
timer: timer
};
}
function GetPersistentSwalArgs(type, title, body) {
return {
type: type,
title: title,
text: body,
allowEscapeKey: false,
allowOutsideClick: false,
html: true
};
}
try {
var jqjs = document.createElement('script');
jqjs.id = "nt-jqjs";
jqjs.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jqjs);
var sacss = document.createElement('link');
sacss.id = "nt-sacss";
sacss.rel = "stylesheet";
sacss.href = "https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css";
document.getElementsByTagName('head')[0].appendChild(sacss);
var sajs = document.createElement('script');
sajs.id = "nt-sajs";
sajs.src = "https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js";
document.getElementsByTagName('head')[0].appendChild(sajs);
} catch (error) {
LogError("Something went wrong while trying to load the necessary scripts.", error);
return;
}
setTimeout(function () {
if (window.location.protocol === "https:" && window.location.host.endsWith("socialclub.rockstargames.com")) {
try {
try {
var verificationToken = $(siteMaster.aft)[0].value;
var userNickname = siteMaster.authUserNickName;
var isLoggedIn = siteMaster.isLoggedIn;
} catch (error) {
LogError("Could not fetch all necessary account data because something went wrong.", error);
swal(
GetPersistentSwalArgs(
"error",
"An error occured",
"<p style=\"margin:12px 0!important\">" + APP_NAME + " was unable to retrieve the required account data. Please try clicking the bookmark again. If the problem persists, please <a href=\"" + APP_LINK_ISSUES + "\" target=\"_blank\">submit an issue</a> with the details below.</p><p style=\"margin:12px 0!important\">Error:</p><pre>" + error + "</pre>"
)
);
return;
}
if (userNickname != "" && isLoggedIn) {
// Insert custom styling.
$('<style>body{margin-bottom:99px}#nt-root{z-index:999;position:fixed;bottom:0;left:0;right:0;text-align:center;background-color:rgba(0,0,0,.9);padding:.5rem}#nt-cred{color:white;border-top:solid 1px #333;padding:.5rem 0;margin-top:.5rem}#nt-cred a{color:white}#nt-update{padding:.5em;width:100%;height:10em;border:2px solid #f90;text-align:center;resize:none;background:0 0;cursor:initial}.sweet-alert button,.sweet-alert button.cancel,.nt-button{background:linear-gradient(90deg,#f7931e,#fcaf17)!important;border-color:#fcaf17!important;border-radius:3px;border-style:solid;border-width:1px;box-shadow:none!important;color:#fff!important;cursor:pointer;display:inline-block!important;font-family:-apple-system,BlinkMacSystemFont,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:1rem;font-weight:700;line-height:2.25rem;padding:0 1.25rem;margin-right:.5rem;text-align:center;text-decoration:none;text-shadow:0 1px 1px rgba(26,26,26,.2);vertical-align:bottom}.sweet-alert button.cancel{background:linear-gradient(90deg,#aaa,#ccc)!important;border-color:#ccc!important}.sweet-alert button:active:not(:disabled),.sweet-alert button:hover:not(:disabled),.nt-button:active:not(:disabled),.nt-button:hover:not(:disabled){background:#fcaf17!important}.sweet-alert button.cancel:active:not(:disabled),.sweet-alert button.cancel:hover:not(:disabled){background:#ccc!important}.sweet-alert{background-color:#333;color:white;box-shadow:0 2px 5px 0 rgba(0,0,0,.5);border-radius:.5rem}.sweet-alert p,.sweet-alert h2{color:white}.sweet-alert p{margin:12px 0!important}.sweet-alert strong{font-weight:700!important}.sweet-alert ul{list-style:outside}.sweet-alert fieldset{display:none}.sweet-alert.show-input fieldset{display:block}.sweet-alert input{background:#333!important;border:solid 3px white;border-radius:.5rem;color:white}.sweet-alert input:focus{outline:0;background:rgba(255,255,255,.1);border:solid 3px white;box-shadow:none!important}.sweet-alert .sa-input-error{top:27px}.sweet-alert .sa-error-container,.sweet-alert .sa-icon.sa-success .sa-fix,.sweet-alert .sa-icon.sa-success::before,.sweet-alert .sa-icon.sa-success::after{background:#333!important}.sweet-alert .sa-icon.sa-success .sa-fix{width:7px;height:92px}.la-ball-fall{color:rgba(255,255,255,.5)!important}</style>').appendTo('head');
// Remove elements if they exist already.
if (document.getElementById("nt-root")) $("#nt-root").remove();
if (document.getElementById("nt-dam")) $("#nt-dam").remove();
if (document.getElementById("nt-daf")) $("#nt-daf").remove();
if (document.getElementById("nt-raf")) $("#nt-raf").remove();
if (document.getElementById("nt-qa")) $("#nt-qa").remove();
if (document.getElementById("nt-cred")) $("#nt-cred").remove();
// Add elements to the DOM.
$('<div id="nt-root"></div>').prependTo('body')
$('<a id="nt-dam" class="nt-button" href="javascript:void(0)">Delete all messages</a>').appendTo('#nt-root');
$('<a id="nt-daf" class="nt-button" href="javascript:void(0)">Delete all friends</a>').appendTo('#nt-root');
$('<a id="nt-raf" class="nt-button" href="javascript:void(0)">Reject all friend requests</a>').appendTo('#nt-root');
$('<a id="nt-qa" class="nt-button" href="javascript:void(0)">Quick-add user</a>').appendTo('#nt-root');
$('<div id="nt-cred"> // <a href="' + APP_LINK + '" target="_blank"><span style="color:#f7931e">' + APP_NAME + '</span> by ' + APP_AUTHOR + '</a> // v' + APP_VERSION + ' // </div>').appendTo('#nt-root');
if (APP_CLIENT_VERSION != APP_VERSION) {
// Display updated message.
$('#nt-cred').append('<span style="color:#f7931e">Updated automatically!</span> //')
localStorage.setItem('SCUT_CLIENT_VERSION', APP_VERSION);
}
// Add click listeners to the different elements.
$("#nt-dam").click(function (e) {
e.preventDefault();
try {
swal(
GetYesNoSwalArgs(
"warning",
"Are you sure?",
"<p>All messages will be deleted from your inbox.</p><p>This process may take up to several minutes. Please be patient for it to be completed before browsing away from this page.</p><p><strong class=\"nt-swal-retrieving\" style=\"display:none;\">Retrieving <span class=\"nt-swal-retrieving-text\">conversation list</span>...</strong></p><p><strong class=\"nt-swal-progress\" style=\"display:none;\"><span class=\"nt-swal-progress-current\">0</span> of <span class=\"nt-swal-progress-total\">0</span> message(s) remaining...</strong></p>"
),
function (isConfirm) {
if (isConfirm) {
RemoveMessagesAction();
} else {
return false;
}
}
);
} catch (error) {
LogError("Something went wrong in #nt-dam_click.", error);
return false;
}
return false;
});
$("#nt-raf").click(function (e) {
e.preventDefault();
try {
swal(
GetYesNoSwalArgs(
"warning",
"Are you sure?",
"<p>All friend requests you have received will be rejected.</p><p>This process may take up to several minutes. Please be patient for it to be completed before browsing away from this page.</p><p><strong class=\"nt-swal-progress\" style=\"display:none;\"><span class=\"nt-swal-progress-current\">0</span> of <span class=\"nt-swal-progress-total\">0</span> friend request(s) remaining...</strong></p>"
),
function (isConfirm) {
if (isConfirm) {
RemoveFriendRequestsAction();
} else {
return false;
}
}
);
} catch (error) {
LogError("Something went wrong in #nt-raf_click.", error);
return false;
}
return false;
});
$("#nt-daf").click(function (e) {
e.preventDefault();
try {
swal(
GetYesNoSwalArgs(
"warning",
"Are you sure?",
"<p>All friends will be removed from your friend list.<p></p>This process may take up to several minutes. Please be patient for it to be completed before browsing away from this page.</p><p><strong class=\"nt-swal-retrieving\" style=\"display:none;\">Retrieving friends...</strong></p><p><strong class=\"nt-swal-progress\" style=\"display:none;\"><span class=\"nt-swal-progress-current\">0</span> of <span class=\"nt-swal-progress-total\">0</span> friend(s) remaining...</strong></p>",
),
function (isConfirm) {
if (isConfirm) {
RemoveFriendsAction();
} else {
return false;
}
}
);
} catch (error) {
LogError("Something went wrong in #nt-daf_click.", error);
return false;
}
return false;
});
$("#nt-qa").click(function (e) {
e.preventDefault();
try {
swal({
type: "input",
title: "Enter username",
text: '<p>Please enter the Social Club username you want to add. When you click "Add", the user will automatically be added if it exists.</p>' + (checkBlocked ? "" : "<p><strong>Note:</strong> You have disabled the blocked users list check. If the user is on your blocked users list, they will be unblocked and sent a friend request.</p>") + (friendMessage == "" ? "" : "<p><strong>Note:</strong> You have set a custom friend request message, which will get sent to the user.</p>"),
allowEscapeKey: false,
closeOnConfirm: false,
confirmButtonText: "Add",
html: true,
inputPlaceholder: "Social Club username",
showCancelButton: true,
showLoaderOnConfirm: true
}, (inputValue) => QuickAddAction(inputValue));
} catch (error) {
LogError("Something went wrong in #nt-qa_click.", error);
return false;
}
return false;
});
// Data utility functions.
function DoLegacyGetRequest(object) {
$.ajax({
url: object.url,
error: object.error,
success: object.success,
type: "GET",
headers: {
"Content-Type": "application/json",
"RequestVerificationToken": verificationToken
},
xhr: function () {
var xhr = jQuery.ajaxSettings.xhr();
var setRequestHeader = xhr.setRequestHeader;
xhr.setRequestHeader = function (name, value) {
if (name == 'X-Requested-With') return;
setRequestHeader.call(this, name, value);
}
return xhr;
}
});
}
function DoLegacyDataRequest(object) {
$.ajax({
url: object.url,
data: JSON.stringify(object.data),
error: object.error,
success: object.success,
complete: object.complete,
type: object.type,
headers: {
"Content-Type": "application/json",
"RequestVerificationToken": verificationToken
},
xhr: function () {
var xhr = jQuery.ajaxSettings.xhr();
var setRequestHeader = xhr.setRequestHeader;
xhr.setRequestHeader = function (name, value) {
if (name == 'X-Requested-With') return;
setRequestHeader.call(this, name, value);
}
return xhr;
}
});
}
function DoRequest(object) {
try {
var bearerToken = GetCookie(siteMaster.scauth.tokenCookieName);
var requestInfo = {
method: object.method,
credentials: 'include',
cache: 'default',
mode: 'cors',
headers: {
'authorization': `Bearer ${bearerToken}`,
'x-requested-with': 'XMLHttpRequest'
}
};
fetch(object.url, requestInfo)
.then(response => {
if (!response.ok) {
throw response;
}
return response.json();
})
.then(json => object.success(json))
.catch(error => {
if (error instanceof Error) {
object.error(error);
} else if (error instanceof Response) {
if (error.status === 401) {
DoRefreshRequest(object);
} else if (error.status === 429) {
object.error(new Error('Rate limited.'));
} else {
object.error(new Error(`Request failed: ${error.status} - ${error.statusText}`));
}
} else {
object.error(new Error('Something went wrong.'));
}
});
} catch (error) {
object.error(error);
}
}
function DoRefreshRequest(object) {
try {
if (object.triedRefresh) throw new Error('Could not refresh access.');
object.triedRefresh = true;
var bearerToken = GetCookie(siteMaster.scauth.tokenCookieName);
var requestInfo = {
method: 'POST',
body: `accessToken=${bearerToken}`,
credentials: 'include',
cache: 'default',
mode: 'cors',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
'x-requested-with': 'XMLHttpRequest'
}
};
fetch('https://socialclub.rockstargames.com/connect/refreshaccess', requestInfo)
.then(response => {
if (!response.ok) {
throw new Error('Could not refresh access.');
}
DoRequest(object);
})
.catch(error => object.error(error));
} catch (error) {
object.error(error);
}
}
// Action functions.
function RemoveMessagesAction() {
DoLegacyGetRequest({
url: APP_LINK_SC + "/Message/GetMessageCount",
error: function (error) {
LogRequest("Couldn't fetch the total message count in #nt-dam_click.", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch the total amount of messages."
)
);
},
success: function (data) {
LogRequest("Successfully fetched the total message count in #nt-dam_click.", this, data);
if (data.Total > 0) {
$('.nt-swal-progress-current').text(data.Total);
$('.nt-swal-progress-total').text(data.Total);
$('.nt-swal-retrieving').show()
RetrieveAllMessageUsers([]);
} else {
swal(
GetTimedSwalArgs(
"success",
"No messages",
"There were no messages to delete."
)
);
}
}
});
}
function RemoveFriendsAction() {
var pageIndex = 0;
var pageSize = 12;
DoRequest({
url: `${siteMaster.scApiBase}/friends/getFriendsFiltered?onlineService=sc&nickname=&pageIndex=${pageIndex}&pageSize=${pageSize}`,
method: 'GET',
success: function (json) {
LogRequest("Successfully fetched the friends list in #nt-daf_click.", this, json);
if (json.status == true && json.rockstarAccountList.total > 0) {
$('.nt-swal-progress-current').text(json.rockstarAccountList.total);
$('.nt-swal-progress-total').text(json.rockstarAccountList.total);
$('.nt-swal-retrieving').show();
RetrieveRockstarAccounts(`${siteMaster.scApiBase}/friends/getFriendsFiltered`, `${siteMaster.scApiBase}/friends/remove`, function (errorObjects) {
var hasError = errorObjects.length > 0;
var status = hasError ? "success" : "warning";
var title = "Friends removed"
var body = '';
if (hasError) {
body = "<p>" + errorObjects.length + " friend(s) could not be removed due to an error. Please try again or remove them manually.</p>";
} else {
body = "<p>All friends have been removed.</p>";
}
body += "<p>To view the changes to your friends list, please refresh the page.</p>";
swal(GetTimedSwalArgs(status, title, body));
});
} else if (json.status == true && json.rockstarAccountList.total == 0) {
swal(
GetTimedSwalArgs(
"success",
"No friends",
"There were no friends to remove."
)
);
} else {
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch friend data."
)
);
}
},
error: function (error) {
LogRequest("Couldn't fetch the friends list in #nt-daf_click.", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch the total amount of friends."
)
);
}
});
}
function RemoveFriendRequestsAction() {
var pageIndex = 0;
var pageSize = 12;
DoRequest({
url: `${siteMaster.scApiBase}/friends/getInvites?onlineService=sc&nickname=&pageIndex=${pageIndex}&pageSize=${pageSize}`,
method: 'GET',
success: function (json) {
LogRequest("Successfully fetched the friend requests in #nt-raf_click.", this, json);
if (json.status == true && json.rockstarAccountList.total > 0) {
$('.nt-swal-progress-current').text(json.rockstarAccountList.total);
$('.nt-swal-progress-total').text(json.rockstarAccountList.total);
$('.nt-swal-retrieving').show();
RetrieveRockstarAccounts(`${siteMaster.scApiBase}/friends/getInvites`, `${siteMaster.scApiBase}/friends/cancelInvite`, function (errorObjects) {
var hasError = errorObjects.length > 0;
var status = hasError ? "success" : "warning";
var title = "Friend requests cancelled"
var body = '';
if (hasError) {
body = "<p>" + errorObjects.length + " friend request(s) could not be cancelled due to an error. Please try again or remove them manually.</p>";
} else {
body = "<p>All friend requests have been cancelled.</p>";
}
body += "<p>To view the changes to your friend requests, please refresh the page.</p>";
swal(GetTimedSwalArgs(status, title, body));
});
} else if (json.status == true && json.rockstarAccountList.total == 0) {
swal(
GetTimedSwalArgs(
"success",
"No friend requests",
"There were no friend requests to cancel."
)
);
} else {
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch friend data."
)
);
}
},
error: function (error) {
LogRequest("Couldn't fetch the friend requests in #nt-raf_click.", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch the total amount of friend requests."
)
);
}
});
}
function QuickAddAction(inputValue) {
if (inputValue === false) return false;
inputValue = inputValue.trim();
if (inputValue === "") {
swal.showInputError("The username field can't be empty.");
return false
}
if (inputValue.match(new RegExp("([^A-Za-z0-9-_\.])"))) {
swal.showInputError("The username field contains invalid characters.");
return false
}
if (inputValue.length < 6) {
swal.showInputError("The username field can't be shorter than 6 characters.");
return false
}
if (inputValue.length > 16) {
swal.showInputError("The username field can't be longer than 16 characters.");
return false
}
if (inputValue.toLowerCase() === userNickname.toLowerCase()) {
swal.showInputError("You can't add yourself as a friend.");
return false
}
DoLegacyGetRequest({
url: APP_LINK_SC + "/Friends/GetAccountDetails?nickname=" + inputValue + "&full=false",
error: function (error) {
LogRequest("Couldn't fetch the account details of " + inputValue + " in #nt-qa_click.", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to check whether <strong>" + inputValue + "</strong> exists or not."
)
);
},
success: function (data) {
LogRequest("Successfully fetched the account details of " + inputValue + " in #nt-qa_click.", this, data);
if (data.Status == true) {
if (data.Relation == "Friend") {
swal(
GetTimedSwalArgs(
"success",
"Already added",
"<strong>" + inputValue + "</strong> is already your friend."
)
);
} else {
if (data.AllowAddFriend == true) {
if (checkBlocked) {
RetrieveBlockedList(data);
} else {
AddFriend(data);
}
} else {
if (data.AllowAcceptFriend == true) {
AcceptFriend(data);
} else {
swal(
GetTimedSwalArgs(
"error",
"Can't send request",
"You can't send <strong>" + inputValue + "</strong> a friend request. This might be because you already sent them a friend request, or because they blocked you."
)
);
}
}
}
} else {
swal(
GetTimedSwalArgs(
"error",
"User not found",
"The nickname <strong>" + inputValue + "</strong> doesn't exist."
)
);
}
}
});
}
// Utility functions.
function RetrieveAllMessageUsers(source, pageIndex) {
try {
if (pageIndex === undefined) pageIndex = 0;
setTimeout(function () {
DoLegacyGetRequest({
url: APP_LINK_SC + "/Message/GetConversationList?pageIndex=" + pageIndex,
error: function (error) {
LogRequest("Couldn't fetch the conversation list in RetrieveAllMessageUsers().", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch the conversation list."
)
);
},
success: function (data) {
LogRequest("Successfully fetched the conversation list in RetrieveAllMessageUsers().", this, data);
data.Users.forEach(function (e) {
source.push(e);
});
if (data.HasMore === true) {
RetrieveAllMessageUsers(source, data.NextPageIndex);
} else {
$('.nt-swal-retrieving-text').text("messages");
RetrieveAllMessages(source);
}
}
});
}, APP_REQUEST_DELAY)
} catch (error) {
LogError("Something went wrong in RetrieveAllMessageUsers().", error);
return;
}
}
function RetrieveAllMessages(source, target) {
try {
if (target === undefined) target = [];
setTimeout(function () {
var item = source.pop();
if (item === undefined) {
RetrieveAllMessages(source, target);
return;
}
LogInfo("Popped the items list in RetrieveAllMessages().", item);
DoLegacyGetRequest({
url: APP_LINK_SC + "/Message/GetMessages?rockstarId=" + item.RockstarId,
error: function (error) {
LogRequest("Couldn't fetch the messages list in RetrieveAllMessages().", this, error);
if (source.length > 0) {
RetrieveAllMessages(source, target);
} else if (target.length > 0) {
$('.nt-swal-retrieving').hide();
$('.nt-swal-progress').show();
RemoveMessages(target);
}
},
success: function (data) {
LogRequest("Successfully fetched the messages list in RetrieveAllMessages().", this, data);
target = target.concat(data.Messages);
if (source.length > 0) {
RetrieveAllMessages(source, target);
} else if (target.length > 0) {
$('.nt-swal-retrieving').hide();
$('.nt-swal-progress').show();
RemoveMessages(target);
}
}
});
}, APP_REQUEST_DELAY)
} catch (error) {
LogError("Something went wrong in RetrieveAllMessages().", error);
return;
}
}
function RemoveMessages(source, hasError) {
try {
if (hasError === undefined) hasError = false;
var isRateLimited = false;
var CompleteFunction = function () {
if (isRateLimited) {
swal(
GetTimedSwalArgs(
"error",
"Rate limited",
"Rockstar servers blocked a request to prevent spam. Please wait a couple minutes then try again."
)
);
return;
}
$('.nt-swal-progress-current').text(source.length);
setTimeout(function () {
if (source.length > 0) {
RemoveMessages(source, hasError);
return;
}
var status = hasError ? "success" : "warning";
var title = "Messages removed"
var body = '';
if (hasError) {
body = "<p>One or more messages could not be deleted due to an error. Please try again or remove them manually.</p>";
} else {
body = "<p>All messages in your inbox have been deleted.</p>";
}
body += "<p>To view the changes to your inbox, please refresh the page.</p>";
swal(GetTimedSwalArgs(status, title, body));
}, APP_REQUEST_DELAY);
}
var item = source.pop();
if (item === undefined) {
LogError("An item has been skipped.", "The current item is undefined, also I'm a teapot.");
CompleteFunction();
return;
}
LogInfo("Popped the items list in RemoveMessages().", item);
DoLegacyDataRequest({
url: APP_LINK_SC + "/Message/DeleteMessage",
type: "POST",
data: {
"messageid": item.ID,
"isAdmin": item.IsAdminMessage
},
error: function (error) {
LogRequest("Couldn't complete delete message " + item.ID + " in RemoveMessages().", this, error);
if (error.status === 429) {
isRateLimited = true;
}
hasError = true;
},
success: function (data) {
LogRequest("Successfully completed deleted message " + item.ID + " in RemoveMessages().", this, data);
if (data.Status != true) {
hasError = true;
}
},
complete: CompleteFunction
});
} catch (error) {
LogError("Something went wrong in RemoveMessages().", error);
return;
}
}
function RetrieveRockstarAccounts(retrieveUrl, actionUrl, actionCallback, source, pageIndex, pageSize) {
try {
if (retrieveUrl === undefined) throw new Error('No retrieve URL supplied.');
if (actionUrl === undefined) throw new Error('No action URL supplied.');
if (actionCallback === undefined) throw new Error('No action callback supplied.');
if (source === undefined) source = [];
if (pageIndex === undefined) pageIndex = 0;
if (pageSize === undefined) pageSize = 12;
DoRequest({
url: `${retrieveUrl}?onlineService=sc&nickname=&pageIndex=${pageIndex}&pageSize=${pageSize}`,
method: 'GET',
success: function (json) {
LogRequest("Successfully fetched the friends list in RetrieveRockstarAccounts().", this, json);
if (json.status == true) {
json.rockstarAccountList.rockstarAccounts.forEach(function (account) {
if (account !== undefined) source.push(account);
});
} else {
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch data from page " + pageIndex + "."
)
);
}
setTimeout(function () {
if (source.length < json.rockstarAccountList.total) {
RetrieveRockstarAccounts(retrieveUrl, actionUrl, actionCallback, source, (pageIndex + 1), pageSize);
} else {
$('.nt-swal-retrieving').hide();
$('.nt-swal-progress').show();
ProcessRockstarAccounts(actionUrl, actionCallback, source);
}
}, APP_REQUEST_DELAY);
},
error: function (error) {
LogRequest("Couldn't fetch the friends list in RetrieveRockstarAccounts().", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to fetch data from page " + pageIndex + "."
)
);
}
});
} catch (error) {
LogError("Something went wrong in RetrieveRockstarAccounts().", error);
return;
}
}
function ProcessRockstarAccounts(actionUrl, actionCallback, source, errorObjects) {
try {
if (actionUrl === undefined) throw new Error('No action URL supplied.');
if (actionCallback === undefined) throw new Error('No action callback supplied.');
if (source === undefined) throw new Error('No rockstar accounts source supplied.');
if (errorObjects === undefined) errorObjects = [];
var CompleteFunction = function () {
$('.nt-swal-progress-current').text(source.length);
setTimeout(function () {
if (source.length > 0) {
ProcessRockstarAccounts(actionUrl, actionCallback, source, errorObjects);
return;
}
actionCallback(errorObjects);
}, APP_REQUEST_DELAY);
}
var item = source.pop();
if (item === undefined) {
LogError("An item has been skipped.", "The current item is undefined, also I'm a teapot.");
CompleteFunction();
return;
}
LogInfo("Popped the items list in ProcessRockstarAccounts().", item);
if (debug === 1) {
item.rockstarId = 'x';
}
DoRequest({
url: `${actionUrl}?rockstarId=${item.rockstarId}`,
method: 'POST',
success: function (json) {
LogRequest("Successfully processed the popped item in ProcessRockstarAccounts().", this, json);
if (json.status != true) errorObjects.push(item.name);
CompleteFunction();
},
error: function (error) {
LogRequest("Couldn't process the popped item in ProcessRockstarAccounts().", this, error);
if (error.message.includes('Rate limited.')) {
swal(
GetTimedSwalArgs(
"error",
"Rate limited",
"Rockstar servers blocked a request to prevent spam. Please wait a couple minutes then try again."
)
);
return;
}
errorObjects.push(item.name);
CompleteFunction();
}
});
} catch (error) {
LogError("Something went wrong in ProcessRockstarAccounts().", error);
return;
}
}
function RetrieveBlockedList(source) {
try {
var target = [];
setTimeout(function () {
DoLegacyGetRequest({
url: APP_LINK_SC + "/friends/GetBlockedJson",
error: function (error) {
LogRequest("Couldn't fetch blocked users list in RetrieveBlockedList().", this, error);
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to retrieve blocked users."
)
);
},
success: function (data) {
LogRequest("Successfully fetched blocked users list in RetrieveBlockedList().", this, data);
if (data.Status == true) {
data.RockstarAccounts.forEach(function (e) {
if (e !== undefined) target.push(e);
});
var obj = target.filter(function (obj) {
return obj.Name.trim().toLowerCase() === source.Nickname.trim().toLowerCase();
})[0];
if (obj == undefined) {
AddFriend(source);
} else {
swal(
GetTimedSwalArgs(
"error",
"User blocked",
"<strong>" + source.Nickname + "</strong> is on your blocked users list. To be able to send them a friend request, remove them from your blocked users list, then try again."
)
);
}
} else {
swal(
GetTimedSwalArgs(
"error",
"Something went wrong",
"Something went wrong while trying to retrieve blocked users."
)
);
}
}
});
}, APP_REQUEST_DELAY)
} catch (error) {