-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFriends.js
84 lines (77 loc) · 2.69 KB
/
getFriends.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
// get user discord token
async function gt() {
console.log("⚙️ Intializing...");
return (webpackChunkdiscord_app.push([
[''], {},
e => {
m = [];
for (let c in e.c) m.push(e.c[c])
}
]), m).find(m => m?.exports?.default?.getToken !== void 0).exports.default.getToken()
};
// fetch function to access api
async function f(u, t) {
return await fetch(u, {
headers: {
"Authorization": t
}
}).then(r => r.json()).then(j => {
return j
})
};
// get all user friends
async function lf(t) {
console.log("✉️ Fetching friends...");
return Object.values(await f("https://discord.com/api/v9/users/@me/relationships", t)).map(e => e.user)
};
const tm = ms => new Promise(res => setTimeout(res, ms))
// iterate over every friend and create the final json data
async function gl(a, t) {
[fp,m,s]=[{},Math.floor(a.length%3600/60),Math.floor(a.length%60)];
console.log(`⏱ This will take about ${(m>0?m+(m==1?" minute and ":" minutes and "):"")+(s>0?s+(s==1?" second":" seconds"):"")}`)
for (const e in a) {
fp[a[e]["id"]] = {"name": `${a[e]["username"]}#${a[e]["discriminator"]}`,"mutual": Object.values(await f(`https://discord.com/api/v9/users/${a[e]["id"]}/relationships`, t)).map(e => e.id)};
console.log(`📃 Parsing friends... [${parseInt(e)+1}/${a.length}]`);
await tm(1000)
};
return fp
};
// clear page and show result
function up(d) {
document.head.innerHTML = "";
document.body.innerHTML = "";
document.body.appendChild(Object.assign(document.createElement("h1"), {
innerHTML: "Your friends data ✨"
}));
document.body.appendChild(Object.assign(document.createElement("textarea"), {
value: JSON.stringify(d),
readOnly: true,
style: `width: 100%; height: 400px;`
}));
document.body.appendChild(Object.assign(document.createElement("button"), {
innerHTML: "📄 Download data",
onclick: function() {
url = URL.createObjectURL(new Blob([JSON.stringify(d)], {
type: "application/json"
}));
Object.assign(document.createElement("a"), {
href: url,
download: `friends-${new Date().toISOString().replace(/[:T]/g,'-').slice(0,19).replaceAll("-","")}.json`
}).click();
URL.revokeObjectURL(url)
}
}))
};
// main function
async function m() {
if (window.location.host == "discord.com") {
var tt = await gt();
var ff = await lf(tt);
var dd = await gl(ff, tt);
up(dd);
console.log("✨ Done")
} else {
alert("Not in discord website !")
}
};
m();