Advertisement
d3z3n0v3

Untitled

May 2nd, 2021
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.77 KB | None | 0 0
  1. function Init(friendMessage, checkBlocked, debug) {
  2. const APP_VERSION = 31;
  3. const APP_NAME = "Social Club Utility Tool";
  4. const APP_NAME_SHORT = "SCUT";
  5. const APP_AUTHOR = "Senex";
  6. const APP_LINK = "https://github.com/Senexis/Social-Club-Tool";
  7. const APP_LINK_ISSUES = "https://github.com/Senexis/Social-Club-Tool/issues/new";
  8. const APP_LINK_SC = "https://" + window.location.host;
  9. const APP_CLIENT_VERSION = localStorage.getItem('SCUT_CLIENT_VERSION');
  10. const APP_REQUEST_DELAY = 1000;
  11.  
  12. try {
  13. console.log.apply(console, ["%c " + APP_NAME + " %cv" + APP_VERSION + " by " + APP_AUTHOR + " %c " + APP_LINK, "background:#000000;color:#f90", "background:#000000;color:#ffffff", ""]);
  14. } catch (error) {
  15. console.log(APP_NAME + " v" + APP_VERSION + " by " + APP_AUTHOR + " - " + APP_LINK);
  16. }
  17.  
  18. if (friendMessage === undefined) friendMessage = "";
  19. friendMessage = friendMessage.replace(/\\\"/g, '').replace(/\"/g, '').replace(/\s\s+/g, ' ').trim();
  20.  
  21. if (checkBlocked === undefined) checkBlocked = 1;
  22. if (debug === undefined) debug = 0;
  23.  
  24. 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().");
  25.  
  26. // Generic helper functions.
  27. function GetCookie(name) {
  28. var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
  29. return v ? v[2] : null;
  30. }
  31.  
  32. // UI utility functions.
  33. function LogInfo(title, body) {
  34. console.groupCollapsed("[" + APP_NAME_SHORT + ": INFO] " + title);
  35. console.log(body);
  36. console.groupEnd();
  37. }
  38.  
  39. function LogError(title, body) {
  40. console.groupCollapsed("[" + APP_NAME_SHORT + ": ERROR] " + title);
  41. console.error(body);
  42. console.groupEnd();
  43. }
  44.  
  45. function LogRequest(title, request, response) {
  46. console.groupCollapsed("[" + APP_NAME_SHORT + ": AJAX] " + title);
  47. console.group("Request");
  48. console.log(request);
  49. console.groupEnd();
  50. console.group("Response");
  51. console.log(response);
  52. console.groupEnd();
  53. console.groupEnd();
  54. }
  55.  
  56. function GetYesNoSwalArgs(type, title, body) {
  57. return {
  58. type: type,
  59. title: title,
  60. text: body,
  61.  
  62. allowEscapeKey: false,
  63. cancelButtonText: "No",
  64. closeOnConfirm: false,
  65. confirmButtonColor: "#DD6B55",
  66. confirmButtonText: "Yes",
  67. html: true,
  68. showCancelButton: true,
  69. showLoaderOnConfirm: true
  70. };
  71. }
  72.  
  73. function GetTimedSwalArgs(type, title, body, timer) {
  74. if (type === "success") timer = 5000;
  75. if (type === "error") timer = 60000;
  76. if (timer === undefined) timer = 5000;
  77.  
  78. return {
  79. type: type,
  80. title: title,
  81. text: body,
  82.  
  83. allowOutsideClick: true,
  84. html: true,
  85. timer: timer
  86. };
  87. }
  88.  
  89. function GetPersistentSwalArgs(type, title, body) {
  90. return {
  91. type: type,
  92. title: title,
  93. text: body,
  94.  
  95. allowEscapeKey: false,
  96. allowOutsideClick: false,
  97. html: true
  98. };
  99. }
  100.  
  101. try {
  102. var jqjs = document.createElement('script');
  103. jqjs.id = "nt-jqjs";
  104. jqjs.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js";
  105. document.getElementsByTagName('head')[0].appendChild(jqjs);
  106.  
  107. var sacss = document.createElement('link');
  108. sacss.id = "nt-sacss";
  109. sacss.rel = "stylesheet";
  110. sacss.href = "https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css";
  111. document.getElementsByTagName('head')[0].appendChild(sacss);
  112.  
  113. var sajs = document.createElement('script');
  114. sajs.id = "nt-sajs";
  115. sajs.src = "https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js";
  116. document.getElementsByTagName('head')[0].appendChild(sajs);
  117. } catch (error) {
  118. LogError("Something went wrong while trying to load the necessary scripts.", error);
  119. return;
  120. }
  121.  
  122. setTimeout(function () {
  123. if (window.location.protocol === "https:" && window.location.host.endsWith("socialclub.rockstargames.com")) {
  124. try {
  125. try {
  126. var verificationToken = $(siteMaster.aft)[0].value;
  127. var userNickname = siteMaster.authUserNickName;
  128. var isLoggedIn = siteMaster.isLoggedIn;
  129. } catch (error) {
  130. LogError("Could not fetch all necessary account data because something went wrong.", error);
  131.  
  132. swal(
  133. GetPersistentSwalArgs(
  134. "error",
  135. "An error occured",
  136. "<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>"
  137. )
  138. );
  139.  
  140. return;
  141. }
  142.  
  143. if (userNickname != "" && isLoggedIn) {
  144. // Insert custom styling.
  145. $('<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');
  146.  
  147. // Remove elements if they exist already.
  148. if (document.getElementById("nt-root")) $("#nt-root").remove();
  149. if (document.getElementById("nt-dam")) $("#nt-dam").remove();
  150. if (document.getElementById("nt-daf")) $("#nt-daf").remove();
  151. if (document.getElementById("nt-raf")) $("#nt-raf").remove();
  152. if (document.getElementById("nt-qa")) $("#nt-qa").remove();
  153. if (document.getElementById("nt-cred")) $("#nt-cred").remove();
  154.  
  155. // Add elements to the DOM.
  156. $('<div id="nt-root"></div>').prependTo('body')
  157. $('<a id="nt-dam" class="nt-button" href="javascript:void(0)">Delete all messages</a>').appendTo('#nt-root');
  158. $('<a id="nt-daf" class="nt-button" href="javascript:void(0)">Delete all friends</a>').appendTo('#nt-root');
  159. $('<a id="nt-raf" class="nt-button" href="javascript:void(0)">Reject all friend requests</a>').appendTo('#nt-root');
  160. $('<a id="nt-qa" class="nt-button" href="javascript:void(0)">Quick-add user</a>').appendTo('#nt-root');
  161. $('<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');
  162.  
  163. if (APP_CLIENT_VERSION != APP_VERSION) {
  164. // Display updated message.
  165. $('#nt-cred').append('<span style="color:#f7931e">Updated automatically!</span> //')
  166. localStorage.setItem('SCUT_CLIENT_VERSION', APP_VERSION);
  167. }
  168.  
  169. // Add click listeners to the different elements.
  170. $("#nt-dam").click(function (e) {
  171. e.preventDefault();
  172.  
  173. try {
  174. swal(
  175. GetYesNoSwalArgs(
  176. "warning",
  177. "Are you sure?",
  178. "<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>"
  179. ),
  180. function (isConfirm) {
  181. if (isConfirm) {
  182. RemoveMessagesAction();
  183. } else {
  184. return false;
  185. }
  186. }
  187. );
  188. } catch (error) {
  189. LogError("Something went wrong in #nt-dam_click.", error);
  190. return false;
  191. }
  192.  
  193. return false;
  194. });
  195.  
  196. $("#nt-raf").click(function (e) {
  197. e.preventDefault();
  198.  
  199. try {
  200. swal(
  201. GetYesNoSwalArgs(
  202. "warning",
  203. "Are you sure?",
  204. "<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>"
  205. ),
  206. function (isConfirm) {
  207. if (isConfirm) {
  208. RemoveFriendRequestsAction();
  209. } else {
  210. return false;
  211. }
  212. }
  213. );
  214. } catch (error) {
  215. LogError("Something went wrong in #nt-raf_click.", error);
  216. return false;
  217. }
  218.  
  219. return false;
  220. });
  221.  
  222. $("#nt-daf").click(function (e) {
  223. e.preventDefault();
  224.  
  225. try {
  226. swal(
  227. GetYesNoSwalArgs(
  228. "warning",
  229. "Are you sure?",
  230. "<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>",
  231. ),
  232. function (isConfirm) {
  233. if (isConfirm) {
  234. RemoveFriendsAction();
  235. } else {
  236. return false;
  237. }
  238. }
  239. );
  240. } catch (error) {
  241. LogError("Something went wrong in #nt-daf_click.", error);
  242. return false;
  243. }
  244.  
  245. return false;
  246. });
  247.  
  248. $("#nt-qa").click(function (e) {
  249. e.preventDefault();
  250.  
  251. try {
  252. swal({
  253. type: "input",
  254. title: "Enter username",
  255. 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>"),
  256.  
  257. allowEscapeKey: false,
  258. closeOnConfirm: false,
  259. confirmButtonText: "Add",
  260. html: true,
  261. inputPlaceholder: "Social Club username",
  262. showCancelButton: true,
  263. showLoaderOnConfirm: true
  264. }, (inputValue) => QuickAddAction(inputValue));
  265. } catch (error) {
  266. LogError("Something went wrong in #nt-qa_click.", error);
  267. return false;
  268. }
  269.  
  270. return false;
  271. });
  272.  
  273. // Data utility functions.
  274. function DoLegacyGetRequest(object) {
  275. $.ajax({
  276. url: object.url,
  277. error: object.error,
  278. success: object.success,
  279. type: "GET",
  280. headers: {
  281. "Content-Type": "application/json",
  282. "__RequestVerificationToken": verificationToken
  283. },
  284. xhr: function () {
  285. var xhr = jQuery.ajaxSettings.xhr();
  286. var setRequestHeader = xhr.setRequestHeader;
  287.  
  288. xhr.setRequestHeader = function (name, value) {
  289. if (name == 'X-Requested-With') return;
  290. setRequestHeader.call(this, name, value);
  291. }
  292.  
  293. return xhr;
  294. }
  295. });
  296. }
  297.  
  298. function DoLegacyDataRequest(object) {
  299. $.ajax({
  300. url: object.url,
  301. data: JSON.stringify(object.data),
  302. error: object.error,
  303. success: object.success,
  304. complete: object.complete,
  305. type: object.type,
  306. headers: {
  307. "Content-Type": "application/json",
  308. "RequestVerificationToken": verificationToken
  309. },
  310. xhr: function () {
  311. var xhr = jQuery.ajaxSettings.xhr();
  312. var setRequestHeader = xhr.setRequestHeader;
  313.  
  314. xhr.setRequestHeader = function (name, value) {
  315. if (name == 'X-Requested-With') return;
  316. setRequestHeader.call(this, name, value);
  317. }
  318.  
  319. return xhr;
  320. }
  321. });
  322. }
  323.  
  324. function DoRequest(object) {
  325. try {
  326. var bearerToken = GetCookie(siteMaster.scauth.tokenCookieName);
  327. var requestInfo = {
  328. method: object.method,
  329. credentials: 'include',
  330. cache: 'default',
  331. mode: 'cors',
  332. headers: {
  333. 'authorization': `Bearer ${bearerToken}`,
  334. 'x-requested-with': 'XMLHttpRequest'
  335. }
  336. };
  337.  
  338. fetch(object.url, requestInfo)
  339. .then(response => {
  340. if (!response.ok) {
  341. throw response;
  342. }
  343.  
  344. return response.json();
  345. })
  346. .then(json => object.success(json))
  347. .catch(error => {
  348. if (error instanceof Error) {
  349. object.error(error);
  350. } else if (error instanceof Response) {
  351. if (error.status === 401) {
  352. DoRefreshRequest(object);
  353. } else if (error.status === 429) {
  354. object.error(new Error('Rate limited.'));
  355. } else {
  356. object.error(new Error(`Request failed: ${error.status} - ${error.statusText}`));
  357. }
  358. } else {
  359. object.error(new Error('Something went wrong.'));
  360. }
  361. });
  362. } catch (error) {
  363. object.error(error);
  364. }
  365. }
  366.  
  367. function DoRefreshRequest(object) {
  368. try {
  369. if (object.triedRefresh) throw new Error('Could not refresh access.');
  370. object.triedRefresh = true;
  371.  
  372. var bearerToken = GetCookie(siteMaster.scauth.tokenCookieName);
  373. var requestInfo = {
  374. method: 'POST',
  375. body: `accessToken=${bearerToken}`,
  376. credentials: 'include',
  377. cache: 'default',
  378. mode: 'cors',
  379. headers: {
  380. 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
  381. 'x-requested-with': 'XMLHttpRequest'
  382. }
  383. };
  384.  
  385. fetch('https://socialclub.rockstargames.com/connect/refreshaccess', requestInfo)
  386. .then(response => {
  387. if (!response.ok) {
  388. throw new Error('Could not refresh access.');
  389. }
  390.  
  391. DoRequest(object);
  392. })
  393. .catch(error => object.error(error));
  394. } catch (error) {
  395. object.error(error);
  396. }
  397. }
  398.  
  399. // Action functions.
  400. function RemoveMessagesAction() {
  401. DoLegacyGetRequest({
  402. url: APP_LINK_SC + "/Message/GetMessageCount",
  403. error: function (error) {
  404. LogRequest("Couldn't fetch the total message count in #nt-dam_click.", this, error);
  405.  
  406. swal(
  407. GetTimedSwalArgs(
  408. "error",
  409. "Something went wrong",
  410. "Something went wrong while trying to fetch the total amount of messages."
  411. )
  412. );
  413. },
  414. success: function (data) {
  415. LogRequest("Successfully fetched the total message count in #nt-dam_click.", this, data);
  416.  
  417. if (data.Total > 0) {
  418. $('.nt-swal-progress-current').text(data.Total);
  419. $('.nt-swal-progress-total').text(data.Total);
  420. $('.nt-swal-retrieving').show()
  421. RetrieveAllMessageUsers([]);
  422. } else {
  423. swal(
  424. GetTimedSwalArgs(
  425. "success",
  426. "No messages",
  427. "There were no messages to delete."
  428. )
  429. );
  430. }
  431. }
  432. });
  433. }
  434.  
  435. function RemoveFriendsAction() {
  436. var pageIndex = 0;
  437. var pageSize = 12;
  438.  
  439. DoRequest({
  440. url: `${siteMaster.scApiBase}/friends/getFriendsFiltered?onlineService=sc&nickname=&pageIndex=${pageIndex}&pageSize=${pageSize}`,
  441. method: 'GET',
  442. success: function (json) {
  443. LogRequest("Successfully fetched the friends list in #nt-daf_click.", this, json);
  444.  
  445. if (json.status == true && json.rockstarAccountList.total > 0) {
  446. $('.nt-swal-progress-current').text(json.rockstarAccountList.total);
  447. $('.nt-swal-progress-total').text(json.rockstarAccountList.total);
  448. $('.nt-swal-retrieving').show();
  449.  
  450. RetrieveRockstarAccounts(`${siteMaster.scApiBase}/friends/getFriendsFiltered`, `${siteMaster.scApiBase}/friends/remove`, function (errorObjects) {
  451. var hasError = errorObjects.length > 0;
  452. var status = hasError ? "success" : "warning";
  453. var title = "Friends removed"
  454. var body = '';
  455.  
  456. if (hasError) {
  457. body = "<p>" + errorObjects.length + " friend(s) could not be removed due to an error. Please try again or remove them manually.</p>";
  458. } else {
  459. body = "<p>All friends have been removed.</p>";
  460. }
  461.  
  462. body += "<p>To view the changes to your friends list, please refresh the page.</p>";
  463.  
  464. swal(GetTimedSwalArgs(status, title, body));
  465. });
  466. } else if (json.status == true && json.rockstarAccountList.total == 0) {
  467. swal(
  468. GetTimedSwalArgs(
  469. "success",
  470. "No friends",
  471. "There were no friends to remove."
  472. )
  473. );
  474. } else {
  475. swal(
  476. GetTimedSwalArgs(
  477. "error",
  478. "Something went wrong",
  479. "Something went wrong while trying to fetch friend data."
  480. )
  481. );
  482. }
  483. },
  484. error: function (error) {
  485. LogRequest("Couldn't fetch the friends list in #nt-daf_click.", this, error);
  486.  
  487. swal(
  488. GetTimedSwalArgs(
  489. "error",
  490. "Something went wrong",
  491. "Something went wrong while trying to fetch the total amount of friends."
  492. )
  493. );
  494. }
  495. });
  496. }
  497.  
  498. function RemoveFriendRequestsAction() {
  499. var pageIndex = 0;
  500. var pageSize = 12;
  501.  
  502. DoRequest({
  503. url: `${siteMaster.scApiBase}/friends/getInvites?onlineService=sc&nickname=&pageIndex=${pageIndex}&pageSize=${pageSize}`,
  504. method: 'GET',
  505. success: function (json) {
  506. LogRequest("Successfully fetched the friend requests in #nt-raf_click.", this, json);
  507.  
  508. if (json.status == true && json.rockstarAccountList.total > 0) {
  509. $('.nt-swal-progress-current').text(json.rockstarAccountList.total);
  510. $('.nt-swal-progress-total').text(json.rockstarAccountList.total);
  511. $('.nt-swal-retrieving').show();
  512.  
  513. RetrieveRockstarAccounts(`${siteMaster.scApiBase}/friends/getInvites`, `${siteMaster.scApiBase}/friends/cancelInvite`, function (errorObjects) {
  514. var hasError = errorObjects.length > 0;
  515. var status = hasError ? "success" : "warning";
  516. var title = "Friend requests cancelled"
  517. var body = '';
  518.  
  519. if (hasError) {
  520. body = "<p>" + errorObjects.length + " friend request(s) could not be cancelled due to an error. Please try again or remove them manually.</p>";
  521. } else {
  522. body = "<p>All friend requests have been cancelled.</p>";
  523. }
  524.  
  525. body += "<p>To view the changes to your friend requests, please refresh the page.</p>";
  526.  
  527. swal(GetTimedSwalArgs(status, title, body));
  528. });
  529. } else if (json.status == true && json.rockstarAccountList.total == 0) {
  530. swal(
  531. GetTimedSwalArgs(
  532. "success",
  533. "No friend requests",
  534. "There were no friend requests to cancel."
  535. )
  536. );
  537. } else {
  538. swal(
  539. GetTimedSwalArgs(
  540. "error",
  541. "Something went wrong",
  542. "Something went wrong while trying to fetch friend data."
  543. )
  544. );
  545. }
  546. },
  547. error: function (error) {
  548. LogRequest("Couldn't fetch the friend requests in #nt-raf_click.", this, error);
  549.  
  550. swal(
  551. GetTimedSwalArgs(
  552. "error",
  553. "Something went wrong",
  554. "Something went wrong while trying to fetch the total amount of friend requests."
  555. )
  556. );
  557. }
  558. });
  559. }
  560.  
  561. function QuickAddAction(inputValue) {
  562. if (inputValue === false) return false;
  563. inputValue = inputValue.trim();
  564.  
  565. if (inputValue === "") {
  566. swal.showInputError("The username field can't be empty.");
  567. return false
  568. }
  569.  
  570. if (inputValue.match(new RegExp("([^A-Za-z0-9-_\.])"))) {
  571. swal.showInputError("The username field contains invalid characters.");
  572. return false
  573. }
  574.  
  575. if (inputValue.length < 6) {
  576. swal.showInputError("The username field can't be shorter than 6 characters.");
  577. return false
  578. }
  579.  
  580. if (inputValue.length > 16) {
  581. swal.showInputError("The username field can't be longer than 16 characters.");
  582. return false
  583. }
  584.  
  585. if (inputValue.toLowerCase() === userNickname.toLowerCase()) {
  586. swal.showInputError("You can't add yourself as a friend.");
  587. return false
  588. }
  589.  
  590. DoLegacyGetRequest({
  591. url: APP_LINK_SC + "/Friends/GetAccountDetails?nickname=" + inputValue + "&full=false",
  592. error: function (error) {
  593. LogRequest("Couldn't fetch the account details of " + inputValue + " in #nt-qa_click.", this, error);
  594.  
  595. swal(
  596. GetTimedSwalArgs(
  597. "error",
  598. "Something went wrong",
  599. "Something went wrong while trying to check whether <strong>" + inputValue + "</strong> exists or not."
  600. )
  601. );
  602. },
  603. success: function (data) {
  604. LogRequest("Successfully fetched the account details of " + inputValue + " in #nt-qa_click.", this, data);
  605.  
  606. if (data.Status == true) {
  607. if (data.Relation == "Friend") {
  608. swal(
  609. GetTimedSwalArgs(
  610. "success",
  611. "Already added",
  612. "<strong>" + inputValue + "</strong> is already your friend."
  613. )
  614. );
  615. } else {
  616. if (data.AllowAddFriend == true) {
  617. if (checkBlocked) {
  618. RetrieveBlockedList(data);
  619. } else {
  620. AddFriend(data);
  621. }
  622. } else {
  623. if (data.AllowAcceptFriend == true) {
  624. AcceptFriend(data);
  625. } else {
  626. swal(
  627. GetTimedSwalArgs(
  628. "error",
  629. "Can't send request",
  630. "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."
  631. )
  632. );
  633. }
  634. }
  635. }
  636. } else {
  637. swal(
  638. GetTimedSwalArgs(
  639. "error",
  640. "User not found",
  641. "The nickname <strong>" + inputValue + "</strong> doesn't exist."
  642. )
  643. );
  644. }
  645. }
  646. });
  647. }
  648.  
  649. // Utility functions.
  650. function RetrieveAllMessageUsers(source, pageIndex) {
  651. try {
  652. if (pageIndex === undefined) pageIndex = 0;
  653.  
  654. setTimeout(function () {
  655. DoLegacyGetRequest({
  656. url: APP_LINK_SC + "/Message/GetConversationList?pageIndex=" + pageIndex,
  657. error: function (error) {
  658. LogRequest("Couldn't fetch the conversation list in RetrieveAllMessageUsers().", this, error);
  659.  
  660. swal(
  661. GetTimedSwalArgs(
  662. "error",
  663. "Something went wrong",
  664. "Something went wrong while trying to fetch the conversation list."
  665. )
  666. );
  667. },
  668. success: function (data) {
  669. LogRequest("Successfully fetched the conversation list in RetrieveAllMessageUsers().", this, data);
  670.  
  671. data.Users.forEach(function (e) {
  672. source.push(e);
  673. });
  674.  
  675. if (data.HasMore === true) {
  676. RetrieveAllMessageUsers(source, data.NextPageIndex);
  677. } else {
  678. $('.nt-swal-retrieving-text').text("messages");
  679. RetrieveAllMessages(source);
  680. }
  681. }
  682. });
  683. }, APP_REQUEST_DELAY)
  684. } catch (error) {
  685. LogError("Something went wrong in RetrieveAllMessageUsers().", error);
  686. return;
  687. }
  688. }
  689.  
  690. function RetrieveAllMessages(source, target) {
  691. try {
  692. if (target === undefined) target = [];
  693.  
  694. setTimeout(function () {
  695. var item = source.pop();
  696. if (item === undefined) {
  697. RetrieveAllMessages(source, target);
  698. return;
  699. }
  700.  
  701. LogInfo("Popped the items list in RetrieveAllMessages().", item);
  702.  
  703. DoLegacyGetRequest({
  704. url: APP_LINK_SC + "/Message/GetMessages?rockstarId=" + item.RockstarId,
  705. error: function (error) {
  706. LogRequest("Couldn't fetch the messages list in RetrieveAllMessages().", this, error);
  707.  
  708. if (source.length > 0) {
  709. RetrieveAllMessages(source, target);
  710. } else if (target.length > 0) {
  711. $('.nt-swal-retrieving').hide();
  712. $('.nt-swal-progress').show();
  713. RemoveMessages(target);
  714. }
  715. },
  716. success: function (data) {
  717. LogRequest("Successfully fetched the messages list in RetrieveAllMessages().", this, data);
  718.  
  719. target = target.concat(data.Messages);
  720.  
  721. if (source.length > 0) {
  722. RetrieveAllMessages(source, target);
  723. } else if (target.length > 0) {
  724. $('.nt-swal-retrieving').hide();
  725. $('.nt-swal-progress').show();
  726. RemoveMessages(target);
  727. }
  728. }
  729. });
  730. }, APP_REQUEST_DELAY)
  731. } catch (error) {
  732. LogError("Something went wrong in RetrieveAllMessages().", error);
  733. return;
  734. }
  735. }
  736.  
  737. function RemoveMessages(source, hasError) {
  738. try {
  739. if (hasError === undefined) hasError = false;
  740. var isRateLimited = false;
  741.  
  742. var CompleteFunction = function () {
  743. if (isRateLimited) {
  744. swal(
  745. GetTimedSwalArgs(
  746. "error",
  747. "Rate limited",
  748. "Rockstar servers blocked a request to prevent spam. Please wait a couple minutes then try again."
  749. )
  750. );
  751.  
  752. return;
  753. }
  754.  
  755. $('.nt-swal-progress-current').text(source.length);
  756.  
  757. setTimeout(function () {
  758. if (source.length > 0) {
  759. RemoveMessages(source, hasError);
  760. return;
  761. }
  762.  
  763. var status = hasError ? "success" : "warning";
  764. var title = "Messages removed"
  765. var body = '';
  766.  
  767. if (hasError) {
  768. body = "<p>One or more messages could not be deleted due to an error. Please try again or remove them manually.</p>";
  769. } else {
  770. body = "<p>All messages in your inbox have been deleted.</p>";
  771. }
  772.  
  773. body += "<p>To view the changes to your inbox, please refresh the page.</p>";
  774.  
  775. swal(GetTimedSwalArgs(status, title, body));
  776. }, APP_REQUEST_DELAY);
  777. }
  778.  
  779. var item = source.pop();
  780. if (item === undefined) {
  781. LogError("An item has been skipped.", "The current item is undefined, also I'm a teapot.");
  782. CompleteFunction();
  783. return;
  784. }
  785.  
  786. LogInfo("Popped the items list in RemoveMessages().", item);
  787.  
  788. DoLegacyDataRequest({
  789. url: APP_LINK_SC + "/Message/DeleteMessage",
  790. type: "POST",
  791. data: {
  792. "messageid": item.ID,
  793. "isAdmin": item.IsAdminMessage
  794. },
  795. error: function (error) {
  796. LogRequest("Couldn't complete delete message " + item.ID + " in RemoveMessages().", this, error);
  797.  
  798. if (error.status === 429) {
  799. isRateLimited = true;
  800. }
  801.  
  802. hasError = true;
  803. },
  804. success: function (data) {
  805. LogRequest("Successfully completed deleted message " + item.ID + " in RemoveMessages().", this, data);
  806.  
  807. if (data.Status != true) {
  808. hasError = true;
  809. }
  810. },
  811. complete: CompleteFunction
  812. });
  813. } catch (error) {
  814. LogError("Something went wrong in RemoveMessages().", error);
  815. return;
  816. }
  817. }
  818.  
  819. function RetrieveRockstarAccounts(retrieveUrl, actionUrl, actionCallback, source, pageIndex, pageSize) {
  820. try {
  821. if (retrieveUrl === undefined) throw new Error('No retrieve URL supplied.');
  822. if (actionUrl === undefined) throw new Error('No action URL supplied.');
  823. if (actionCallback === undefined) throw new Error('No action callback supplied.');
  824.  
  825. if (source === undefined) source = [];
  826. if (pageIndex === undefined) pageIndex = 0;
  827. if (pageSize === undefined) pageSize = 12;
  828.  
  829. DoRequest({
  830. url: `${retrieveUrl}?onlineService=sc&nickname=&pageIndex=${pageIndex}&pageSize=${pageSize}`,
  831. method: 'GET',
  832. success: function (json) {
  833. LogRequest("Successfully fetched the friends list in RetrieveRockstarAccounts().", this, json);
  834.  
  835. if (json.status == true) {
  836. json.rockstarAccountList.rockstarAccounts.forEach(function (account) {
  837. if (account !== undefined) source.push(account);
  838. });
  839. } else {
  840. swal(
  841. GetTimedSwalArgs(
  842. "error",
  843. "Something went wrong",
  844. "Something went wrong while trying to fetch data from page " + pageIndex + "."
  845. )
  846. );
  847. }
  848.  
  849. setTimeout(function () {
  850. if (source.length < json.rockstarAccountList.total) {
  851. RetrieveRockstarAccounts(retrieveUrl, actionUrl, actionCallback, source, (pageIndex + 1), pageSize);
  852. } else {
  853. $('.nt-swal-retrieving').hide();
  854. $('.nt-swal-progress').show();
  855. ProcessRockstarAccounts(actionUrl, actionCallback, source);
  856. }
  857. }, APP_REQUEST_DELAY);
  858. },
  859. error: function (error) {
  860. LogRequest("Couldn't fetch the friends list in RetrieveRockstarAccounts().", this, error);
  861.  
  862. swal(
  863. GetTimedSwalArgs(
  864. "error",
  865. "Something went wrong",
  866. "Something went wrong while trying to fetch data from page " + pageIndex + "."
  867. )
  868. );
  869. }
  870. });
  871. } catch (error) {
  872. LogError("Something went wrong in RetrieveRockstarAccounts().", error);
  873. return;
  874. }
  875. }
  876.  
  877. function ProcessRockstarAccounts(actionUrl, actionCallback, source, errorObjects) {
  878. try {
  879. if (actionUrl === undefined) throw new Error('No action URL supplied.');
  880. if (actionCallback === undefined) throw new Error('No action callback supplied.');
  881. if (source === undefined) throw new Error('No rockstar accounts source supplied.');
  882.  
  883. if (errorObjects === undefined) errorObjects = [];
  884.  
  885. var CompleteFunction = function () {
  886. $('.nt-swal-progress-current').text(source.length);
  887.  
  888. setTimeout(function () {
  889. if (source.length > 0) {
  890. ProcessRockstarAccounts(actionUrl, actionCallback, source, errorObjects);
  891. return;
  892. }
  893.  
  894. actionCallback(errorObjects);
  895. }, APP_REQUEST_DELAY);
  896. }
  897.  
  898. var item = source.pop();
  899. if (item === undefined) {
  900. LogError("An item has been skipped.", "The current item is undefined, also I'm a teapot.");
  901. CompleteFunction();
  902. return;
  903. }
  904.  
  905. LogInfo("Popped the items list in ProcessRockstarAccounts().", item);
  906.  
  907. if (debug === 1) {
  908. item.rockstarId = 'x';
  909. }
  910.  
  911. DoRequest({
  912. url: `${actionUrl}?rockstarId=${item.rockstarId}`,
  913. method: 'POST',
  914. success: function (json) {
  915. LogRequest("Successfully processed the popped item in ProcessRockstarAccounts().", this, json);
  916.  
  917. if (json.status != true) errorObjects.push(item.name);
  918.  
  919. CompleteFunction();
  920. },
  921. error: function (error) {
  922. LogRequest("Couldn't process the popped item in ProcessRockstarAccounts().", this, error);
  923.  
  924. if (error.message.includes('Rate limited.')) {
  925. swal(
  926. GetTimedSwalArgs(
  927. "error",
  928. "Rate limited",
  929. "Rockstar servers blocked a request to prevent spam. Please wait a couple minutes then try again."
  930. )
  931. );
  932.  
  933. return;
  934. }
  935.  
  936. errorObjects.push(item.name);
  937.  
  938. CompleteFunction();
  939. }
  940. });
  941. } catch (error) {
  942. LogError("Something went wrong in ProcessRockstarAccounts().", error);
  943. return;
  944. }
  945. }
  946.  
  947. function RetrieveBlockedList(source) {
  948. try {
  949. var target = [];
  950.  
  951. setTimeout(function () {
  952. DoLegacyGetRequest({
  953. url: APP_LINK_SC + "/friends/GetBlockedJson",
  954. error: function (error) {
  955. LogRequest("Couldn't fetch blocked users list in RetrieveBlockedList().", this, error);
  956.  
  957. swal(
  958. GetTimedSwalArgs(
  959. "error",
  960. "Something went wrong",
  961. "Something went wrong while trying to retrieve blocked users."
  962. )
  963. );
  964. },
  965. success: function (data) {
  966. LogRequest("Successfully fetched blocked users list in RetrieveBlockedList().", this, data);
  967.  
  968. if (data.Status == true) {
  969. data.RockstarAccounts.forEach(function (e) {
  970. if (e !== undefined) target.push(e);
  971. });
  972.  
  973. var obj = target.filter(function (obj) {
  974. return obj.Name.trim().toLowerCase() === source.Nickname.trim().toLowerCase();
  975. })[0];
  976.  
  977. if (obj == undefined) {
  978. AddFriend(source);
  979. } else {
  980. swal(
  981. GetTimedSwalArgs(
  982. "error",
  983. "User blocked",
  984. "<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."
  985. )
  986. );
  987. }
  988. } else {
  989. swal(
  990. GetTimedSwalArgs(
  991. "error",
  992. "Something went wrong",
  993. "Something went wrong while trying to retrieve blocked users."
  994. )
  995. );
  996. }
  997. }
  998. });
  999. }, APP_REQUEST_DELAY)
  1000. } catch (error) {
  1001. LogError("Something went wrong in RetrieveBlockedList().", error);
  1002. return;
  1003. }
  1004. }
  1005.  
  1006. function AddFriend(source) {
  1007. try {
  1008. DoLegacyDataRequest({
  1009. url: APP_LINK_SC + "/friends/UpdateFriend",
  1010. type: "PUT",
  1011. data: {
  1012. "id": source.RockstarId,
  1013. "op": "addfriend",
  1014. "custommessage": friendMessage
  1015. },
  1016. error: function (error) {
  1017. LogRequest("Couldn't complete add " + source.Nickname + " in AddFriend().", this, error);
  1018.  
  1019. swal(
  1020. GetTimedSwalArgs(
  1021. "error",
  1022. "Something went wrong",
  1023. "Something went wrong trying to add <strong>" + source.Nickname + "</strong>."
  1024. )
  1025. );
  1026. },
  1027. success: function (data) {
  1028. LogRequest("Successfully completed add " + source.Nickname + " in AddFriend().", this, data);
  1029.  
  1030. if (data.Status == true) {
  1031. swal(
  1032. GetTimedSwalArgs(
  1033. "success",
  1034. "User added",
  1035. "<p>A friend request has been sent to <strong>" + source.Nickname + "</strong>.</p><p>To view the changes to your friends list, please refresh the page.</p>",
  1036. )
  1037. );
  1038. } else {
  1039. swal(
  1040. GetTimedSwalArgs(
  1041. "error",
  1042. "Something went wrong",
  1043. "Something went wrong trying to add <strong>" + source.Nickname + "</strong>."
  1044. )
  1045. );
  1046. }
  1047. }
  1048. });
  1049. } catch (error) {
  1050. LogError("Something went wrong in AddFriend().", error);
  1051. return;
  1052. }
  1053. }
  1054.  
  1055. function AcceptFriend(source) {
  1056. try {
  1057. DoLegacyDataRequest({
  1058. url: APP_LINK_SC + "/friends/UpdateFriend",
  1059. type: "PUT",
  1060. data: {
  1061. "id": source.RockstarId,
  1062. "op": "confirm",
  1063. "accept": "true"
  1064. },
  1065. error: function (error) {
  1066. LogRequest("Couldn't complete accept " + source.Nickname + "'s friend request in AcceptFriend().", this, error);
  1067.  
  1068. swal(
  1069. GetTimedSwalArgs(
  1070. "error",
  1071. "Something went wrong",
  1072. "Something went wrong trying to accept <strong>" + source.Nickname + "</strong>'s friend request."
  1073. )
  1074. );
  1075. },
  1076. success: function (data) {
  1077. LogRequest("Successfully completed accept " + source.Nickname + "'s friend request in AcceptFriend().", this, data);
  1078.  
  1079. if (data.Status == true) {
  1080. swal(
  1081. GetTimedSwalArgs(
  1082. "success",
  1083. "User accepted",
  1084. "<p><strong>" + source.Nickname + "</strong> already sent you a friend request, and we accepted it instead of sending a new one.</p><p>To view the changes to your friends list, please refresh the page.</p>",
  1085. )
  1086. );
  1087. } else {
  1088. swal(
  1089. GetTimedSwalArgs(
  1090. "error",
  1091. "Something went wrong",
  1092. "Something went wrong trying to accept <strong>" + source.Nickname + "</strong>'s friend request."
  1093. )
  1094. );
  1095. }
  1096. }
  1097. });
  1098. } catch (error) {
  1099. LogError("Something went wrong in AcceptFriend().", error);
  1100. return;
  1101. }
  1102. }
  1103. } else {
  1104. LogError("In order to use " + APP_NAME + ", you must log into your Social Club account.", "userNickname == \"\" || isLoggedIn != true");
  1105.  
  1106. swal(
  1107. GetPersistentSwalArgs(
  1108. "error",
  1109. "Log in required",
  1110. APP_NAME + " requires you to log in to be able to apply changes to your account. Please log into the account you want to use with " + APP_NAME + ", then click the bookmark again."
  1111. )
  1112. );
  1113. }
  1114. } catch (error) {
  1115. LogError("Something went wrong.", error);
  1116.  
  1117. swal(
  1118. GetPersistentSwalArgs(
  1119. "error",
  1120. "An error occured",
  1121. "<p style=\"margin:12px 0!important\">" + APP_NAME + " was unable to complete your request. 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>"
  1122. )
  1123. );
  1124.  
  1125. return;
  1126. }
  1127. } else {
  1128. LogError("The current website is not a Social Club website and " + APP_NAME + " can't continue.", "window.location.protocol !== \"https:\" || !window.location.host.endsWith(\"socialclub.rockstargames.com\")");
  1129.  
  1130. swal(
  1131. {
  1132. type: "warning",
  1133. title: "Wrong site",
  1134. text: "<p>Whoops, you accidentally activated " + APP_NAME + " on a wrong web page. To use " + APP_NAME + ", first browse to the Social Club website, then click the bookmark again.</p><p>Do you want to go to the Social Club website now?</p>",
  1135.  
  1136. allowOutsideClick: true,
  1137. cancelButtonText: "No",
  1138. closeOnConfirm: false,
  1139. confirmButtonText: "Yes",
  1140. html: true,
  1141. showCancelButton: true
  1142. },
  1143. function () {
  1144. window.location.href = "http://socialclub.rockstargames.com/";
  1145. }
  1146. );
  1147. }
  1148. }, APP_REQUEST_DELAY);
  1149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement