-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevealSocialClubId.user.js
144 lines (131 loc) · 4.15 KB
/
revealSocialClubId.user.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
// ==UserScript==
// @name Reveal R* SCID (RID) on Social Club Profile Page
// @namespace Violentmonkey Scripts
// @version 1.1.3
// @description Adds SCID (RID) to the Social Club profile page, compatible with 2Take1 "Fake Friends" feature, for easy copy and paste into the "scid.cfg" file.
// @author IB_U_Z_Z_A_R_Dl
// @match *://socialclub.rockstargames.com/member/*
// @require https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js
// @grant GM_setClipboard
// @downloadURL https://github.com/Illegal-Services/Reveal_Social_Club_ID/releases/latest/download/revealSocialClubId.user.js
// @supportURL https://github.com/Illegal-Services/Reveal_Social_Club_ID/issues
// @homepageURL https://github.com/Illegal-Services/Reveal_Social_Club_ID
// ==/UserScript==
/*
* CREDITS:
* @poedgirl & @DJMC: Original script authors.
* @IN2Moist: HTML page editing.
*
*/
(function () {
'use strict';
const AUTO_COPY_TO_CLIPBOARD = true;
const TIMEOUT = 10000;
const RETRY_INTERVAL = 1000;
const insertToProfile = (element, htmlContent) => {
// file deepcode ignore DOMXSS: trust
element.innerHTML +=
'<div style="text-align: center;">' +
htmlContent +
'</div>';
};
const fetchProfileData = (element, username) => {
const BEARER_TOKEN = Cookies.get('BearerToken');
if (!BEARER_TOKEN) {
console.error('Bearer token not found. Make sure you are logged in.');
return;
}
fetch(
`https://scapi.rockstargames.com/profile/getprofile?nickname=${username}&maxFriends=3`,
{
method: 'GET',
headers: {
Authorization: `Bearer ${BEARER_TOKEN}`,
'X-Requested-With': 'XMLHttpRequest',
},
}
)
.then((response) => {
if (!response.ok) {
throw new Error(
`Failed to fetch Social Club ID for player "${username}". (HTTP Status: ${response.status})`
);
}
return response.json();
})
.then((data) => {
const scId = data.accounts[0].rockstarAccount.rockstarId;
const scHexId = scId.toString(16);
insertToProfile(
element,
'<p style="margin-bottom: 0;">' +
'<span>' +
'Social Club ID (SCID/RID):' +
'</span>' +
'<br>' +
'<span style="font-family: monospace; user-select: all;">' +
scId +
'</span>' +
'</p>' +
'<hr>' +
'<p style="margin-bottom: 0;">' +
'<span>' +
'2Take1 "Fake Friends" (scid.cfg):' +
'</span>' +
'<br>' +
'<span style="font-family: monospace; user-select: all;">' +
`${username}:${scHexId}` +
'</span>' +
'</p>'
);
if (AUTO_COPY_TO_CLIPBOARD) {
GM_setClipboard(`${username}:${scHexId}`, 'text');
}
})
.catch((error) => {
console.error(error);
insertToProfile(element,
'<p>' +
'Failed to fetch Social Club ID.' +
'</p>'
);
});
};
const waitForProfileHeaderElement = (startTime, username) => {
const element = document.querySelector(
'[class^="ProfileHeader__extraInfo"]'
);
if (
element &&
element.className &&
/^ProfileHeader__extraInfo__\w{5}$/.test(element.className)
) {
fetchProfileData(element, username);
} else if (Date.now() - startTime < TIMEOUT) {
setTimeout(
() => waitForProfileHeaderElement(startTime, username),
RETRY_INTERVAL
);
} else {
console.error(
'Failed to find the profile header element after 10 seconds of retries.'
);
return;
}
};
const extractUsernameFromUrl = () => {
const match = /^\/member\/([a-zA-Z0-9_-]{1,16})(?:\/.*)?$/.exec(
window.location.pathname
);
if (!match || match.length <= 0) {
console.error('No username found in the URL');
return;
}
const username = match[1];
waitForProfileHeaderElement(Date.now(), username);
};
const initialize = () => {
extractUsernameFromUrl();
};
initialize();
})();