From fbc859dae0cc89a9d2e4fc7425b9f95a8349980a Mon Sep 17 00:00:00 2001 From: onezDerv Date: Mon, 30 Sep 2024 05:25:43 -0400 Subject: [PATCH] add unfollow all script --- download.js => download_user.js | 0 unfollow_all.js | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) rename download.js => download_user.js (100%) create mode 100644 unfollow_all.js diff --git a/download.js b/download_user.js similarity index 100% rename from download.js rename to download_user.js diff --git a/unfollow_all.js b/unfollow_all.js new file mode 100644 index 0000000..cc3c9f8 --- /dev/null +++ b/unfollow_all.js @@ -0,0 +1,47 @@ +let tree = [], the, user = '08draven', gek = 0, spamTimeout = 0; + +function getCookie(name) { + const value = `; ${document.cookie}`; + const parts = value.split(`; ${name}=`); + if (parts.length === 2) return parts.pop().split(';').shift(); +} + +async function downloadUser(user) { + for (let i = 0; ; i++) { + let fetchReq = await fetch(`https://api.scratch.mit.edu/users/${user}/followers/?limit=40&offset=${i * 40}`); + let fetchJson = await fetchReq.json(); + if (fetchJson.length < 1) break; + tree = [...tree, ...fetchJson]; + } +} + +async function unfollowUser(user) { + if (spamTimeout > 0) { + spamTimeout--; + return; + } + if (the = tree[gek]) { + the = the.username; + e = await fetch(`https://scratch.mit.edu/site-api/users/followers/${the}/remove/?usernames=${user}`, { + "method": "PUT", + "headers": { + "x-csrftoken": getCookie('scratchcsrftoken') + } + }); + e = await e.json(); + console.log(e); + if (e.success) { + gek++; + } else { + spamTimeout = 20; + } + } else { + console.log("end"); + } +} + +await downloadUser(user); + +setInterval(function () { + unfollowUser(user) +}, 500) \ No newline at end of file