Skip to content

Instantly share code, notes, and snippets.

@thinhbuzz
Last active March 2, 2024 01:52
Show Gist options
  • Save thinhbuzz/4da9f7a5260aff597591416035548ecd to your computer and use it in GitHub Desktop.
Save thinhbuzz/4da9f7a5260aff597591416035548ecd to your computer and use it in GitHub Desktop.
Eliminate a series of pokemon go friends by keyword. Please read the first comment for the running steps.
(async () => {
function deleteFriend(friendId) {
return fetch("https://niantic-social-api.nianticlabs.com/niantic/graphql", {
headers: {
authorization: "Bearer " + localStorage.getItem("sessionToken"),
"content-type": "application/json",
},
body:
'{"query":"mutation RemoveFriendMutation(\\n $input: UnfriendNianticUserRequest!\\n) {\\n unfriendNianticUser(input: $input) {\\n friends {\\n userId\\n nianticId\\n displayName\\n gameProfiles {\\n game\\n codename\\n }\\n avatarUrl\\n }\\n success\\n }\\n}\\n","variables":{"input":{"userId":"' +
friendId +
'"}}}',
method: "POST",
})
.then((response) => response.json())
.catch(Promise.resolve);
}
const {
data: { myNianticFriends: allFriends },
} = await fetch("https://niantic-social-api.nianticlabs.com/niantic/graphql", {
headers: {
authorization: "Bearer " + localStorage.getItem("sessionToken"),
"content-type": "application/json",
},
body: '{"query":"query FriendsQuery {\\n myNianticFriends {\\n userId\\n nianticId\\n displayName\\n avatarUrl\\n gameProfiles {\\n game\\n codename\\n visibility\\n }\\n }\\n}\\n","variables":{}}',
method: "POST",
}).then((response) => response.json());
if (!allFriends.length) {
alert("You don't have friends. hahahaahah");
return;
}
let friendName = prompt("Please enter friend text", "");
if (!friendName) {
alert("Skipped by empty keyword");
return;
}
if (!confirm(`Are you sure to delete all friends whose name contains the keyword "${friendName}"?`)) {
alert("Canceled");
return;
}
friendName = friendName.toLowerCase();
const count = {
processed: 0,
success: 0,
};
for (const friend of allFriends) {
if (!friend.displayName.toLowerCase().startsWith(friendName)) {
continue;
}
const response = await deleteFriend(friend.userId);
console.log(response);
count.processed += 1;
if (response?.data?.unfriendNianticUser?.success) {
count.success += 1;
}
}
alert("Processed: " + count.processed + " friends.\nRemoved: " + count.success + " friends.");
})().catch((error) => alert("Error: " + (error?.messsage || "Something went wrong")));
@thinhbuzz
Copy link
Author

  1. Login to My Niantic Profile at https://my.nianticlabs.com/account
  2. Open console in browser DevTools and paste code above into.
    image
  3. Enter your friend's name keyword when the script asks
  4. Wait for the script to complete and display the popup like below
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment