Created
January 14, 2025 14:10
-
-
Save lucahammer/cb4cc5288765da5987faebeca5171738 to your computer and use it in GitHub Desktop.
This file contains 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
const waitForElemToExist = async (selector) => { | |
const elem = document.querySelector(selector) | |
if (elem) return elem | |
return new Promise(resolve => { | |
const observer = new MutationObserver(() => { | |
const elem = document.querySelector(selector) | |
if (elem) { | |
resolve(elem) | |
observer.disconnect() | |
} | |
}) | |
observer.observe(document.body, { | |
subtree: true, | |
childList: true, | |
}) | |
}) | |
} | |
const unfollow = async () => { | |
//document.getElementById("toggleAdvanced").click() | |
let unfollowCount = 0 | |
let next_unfollow, menu | |
const accounts = '[data-testid="UserCell"]' | |
while (document.querySelectorAll('[data-testid="UserCell"] [data-testid$="-unfollow"]').length > 0) { | |
next_unfollow = document.querySelectorAll(accounts)[0] | |
next_unfollow.scrollIntoView({ | |
'behavior': 'smooth' | |
}) | |
next_unfollow.querySelector('[data-testid$="-unfollow"]').click() | |
menu = await waitForElemToExist('[data-testid="confirmationSheetConfirm"]') | |
menu.click() | |
next_unfollow.remove() | |
unfollowCount++ | |
if (unfollowCount % 10 == 0) console.log(`${new Date().toUTCString()} Unfollowed ${unfollowCount} accounts`) | |
await new Promise((resolve) => setTimeout(resolve, (Math.floor(Math.random() * 200)))) | |
} | |
} | |
unfollow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment