Last active
September 13, 2019 17:35
-
-
Save annatomka/dab38a0e9ef5c6afff402ee82ab78d07 to your computer and use it in GitHub Desktop.
Twitter unfollow people script
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
/* | |
* ATTENTION: This script will unfollow all accounts, you load on your profile page | |
* To do that: | |
* 1. Open your twitter profile following tab: https://twitter.com/YOURUSERNAME/following | |
* 2. Run this script on the console | |
* This script is really simple, it will unfollow only the actual loaded accounts, | |
* so you have to scroll down and rerun the script if you want to unfollow more accounts | |
*/ | |
function delay(timeInMs = 100) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(); | |
}, timeInMs); | |
}); | |
} | |
function getButtons() { | |
const queryString = 'div[data-testid$="unfollow"]'; | |
return document.querySelectorAll(queryString); | |
} | |
async function init() { | |
const unfollowButtons = getButtons(); | |
const maxIterations = unfollowButtons.length; | |
const confirmationButtonSelector = 'div[data-testid="confirmationSheetConfirm"]'; | |
for (var i = 0; i < maxIterations; i++) { | |
const button = unfollowButtons[i]; | |
if (button) { | |
button.click(); | |
let confirmationButton = null; | |
while (true) { | |
await delay(); | |
confirmationButton = document.querySelector(confirmationButtonSelector); | |
if (confirmationButton) { | |
break; | |
} | |
} | |
confirmationButton.click(); | |
while (true) { | |
await delay(); | |
confirmationButton = document.querySelector(confirmationButtonSelector); | |
if (!confirmationButton) { | |
break; | |
} | |
} | |
await delay(3000); | |
} | |
} | |
} | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment