Last active
March 2, 2024 01:52
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My Niantic Profile
at https://my.nianticlabs.com/account