Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Javascript code to unfollow everyone
- CoverMusic
-
100+ posts
Javascript code to unfollow everyone
Hi there.
Do any of you have any javascript code which automatically unfollows everyone so I don't have to manually go through and unfollow people?
Thanks.
Do any of you have any javascript code which automatically unfollows everyone so I don't have to manually go through and unfollow people?
Thanks.
- WojtekGame
-
1000+ posts
Javascript code to unfollow everyone
I was asking the same a while (8 months?) ago for Tim (@TimMcCool), but the code was likely untested.
And yeah it was made with his library and his Python code, and no it didn't work, that's why i said likely untested.
And yeah it was made with his library and his Python code, and no it didn't work, that's why i said likely untested.
- CoverMusic
-
100+ posts
Javascript code to unfollow everyone
Hopefully someone can enlighten us both then with new code 

- AHypnoman
-
1000+ posts
Javascript code to unfollow everyone
// Run this from your browser console const followingList = [] // !! IF YOU AREN'T @CoverMusic CHANGE THIS TO YOUR USERNAME !! Otherwise you'll get 429 hardlocked from the API for a minute :P const username = "CoverMusic" // recursion, not while loop. Scratch API has a max allowed 10 requests per sec async function getFollowers() { // Get + append the next page of followers const followersPage = await fetch("https://api.scratch.mit.edu/users/" + username + "/following?limit=40&offset=" + followingList.length, {"method": "GET",}).then(res => res.json()) followingList.push(...followersPage.map(user => user.username)) // Make sure there could still be more followers, and if not start unfollowing process if (followersPage.length < 40) unfollowAll() else setTimeout(getFollowers, 100) } // Function to finally unfollow function unfollowAll() { console.log("This will take " + followingList.length / 10 + " seconds. Do not close this window!") const csrfToken = getCookie("scratchcsrftoken") unfollowNext(csrfToken) } // Function to unfollow single next user in the list function unfollowNext (csrfToken) { //Get and remove next follower from list, then check const nextFollower = followingList.pop() if (nextFollower) { // PUT unfollow request fetch("https://scratch.mit.edu/site-api/users/followers/" + nextFollower + "/remove/?usernames=" + username, {"method": "PUT", "headers":{"X-CSRFToken": csrfToken, "X-Requested-With": "XMLHttpRequest"}}) setTimeout(()=>unfollowNext(csrfToken),100) } else { console.log("Done!") } } // Simple script for getting cookies function getCookie(name) { const value = "; " + document.cookie const parts = value.split("; " + name + "=") if (parts.length === 2) return parts.pop().split(";").shift() } // Run scripts getFollowers()
Depending on how the API is feeling, you may need to run this more than once.
Last edited by AHypnoman (April 8, 2024 12:42:09)
- CoverMusic
-
100+ posts
Javascript code to unfollow everyone
// Run this from your browser console const followingList = [] // !! IF YOU AREN'T @CoverMusic CHANGE THIS TO YOUR USERNAME !! Otherwise you'll get 429 hardlocked from the API for a minute :P const username = "CoverMusic" // recursion, not while loop. Scratch API has a max allowed 10 requests per sec async function getFollowers() { // Get + append the next page of followers const followersPage = await fetch("https://api.scratch.mit.edu/users/" + username + "/following?limit=40&offset=" + followingList.length, {"method": "GET",}).then(res => res.json()) followingList.push(...followersPage.map(user => user.username)) // Make sure there could still be more followers, and if not start unfollowing process if (followersPage.length < 40) unfollowAll() else setTimeout(getFollowers, 100) } // Function to finally unfollow function unfollowAll() { console.log("This will take " + followingList.length / 10 + " seconds. Do not close this window!") const csrfToken = getCookie("scratchcsrftoken") unfollowNext(csrfToken) } // Function to unfollow single next user in the list function unfollowNext (csrfToken) { //Get and remove next follower from list, then check const nextFollower = followingList.pop() if (nextFollower) { // PUT unfollow request fetch("https://scratch.mit.edu/site-api/users/followers/" + nextFollower + "/remove/?usernames=" + username, {"method": "PUT", "headers":{"X-CSRFToken": csrfToken, "X-Requested-With": "XMLHttpRequest"}}) setTimeout(()=>unfollowNext(csrfToken),100) } else { console.log("Done!") } } // Simple script for getting cookies function getCookie(name) { const value = "; " + document.cookie const parts = value.split("; " + name + "=") if (parts.length === 2) return parts.pop().split(";").shift() } // Run scripts getFollowers()
Depending on how the API is feeling, you may need to run this more than once.
Thanks so much, tried it a few times. Doesn't seem to work.
- Discussion Forums
- » Advanced Topics
-
» Javascript code to unfollow everyone