-
Notifications
You must be signed in to change notification settings - Fork 3
/
delete-friends.js
76 lines (69 loc) · 2.26 KB
/
delete-friends.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
token = "YOUR_TOKEN_HERE";
// how many milliseconds to wait between requests to avoid throttling.
sleepTime = 500;
sleep = async () => {
return new Promise((resolve) => setTimeout(resolve, sleepTime));
};
// Set with your own list
listOfFriendsToDelete = `
friend1,
friend2,
friend3
`;
// Remove single friend
deleteSingleFriend = async (id) => {
const url = `https://social.xboxlive.com/users/xuid(${userID})/people/xuid(${id})`;
return await fetch(url, {
credentials: "include",
headers: {
host: "social.xboxlive.com",
Accept: "application/json",
"content-type": "application/json",
authorization: token,
"x-xbl-contract-version": "3",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "cross-site",
},
origin: "https://www.xbox.com",
referrer: "https://www.xbox.com/",
method: "DELETE",
mode: "cors",
})
.then((result) => {
console.log("SUCCESS delete friend " + id);
return result.ok;
})
.catch((e) => {
console.error("FAIL to delete friend " + id);
});
};
// Get IDs for a comma separated list of gamertags
getIDs = async (friendsToDelete) => {
console.log(friendsToDelete);
console.log(friendsIDbyName);
return friendsToDelete.map((tag) => friendsIDbyName[tag]);
};
// Get IDs for gamertags and use them to step through each one and delete friends
deleteFriends = async () => {
console.log("Starting deletion, please wait...");
const deletingArray = listOfFriendsToDelete.replaceAll("\n", "").split(",");
const ids = await getIDs(deletingArray);
console.log(
"Finished fetching IDs for all gamertags in deletion list. If some failed, delete those manually. Deleting the rest now. Please wait..."
);
console.log(ids);
let deletedCount = 0;
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
console.log("deleting friend", id);
const successfulDeletion = await deleteSingleFriend(id);
deletedCount += successfulDeletion ? 1 : 0;
console.log("...");
await sleep();
}
console.log(`Done! Deleted ${deletedCount} of ${deletingArray.length}`);
return true;
};
console.log("You are going to remove these friends: ", listOfFriendsToDelete);
console.log("If that's ok, enter this command: deleteFriends()");