Skip to content

Instantly share code, notes, and snippets.

@blackhaj
Created April 21, 2023 11:40
Show Gist options
  • Select an option

  • Save blackhaj/1549791d63b5f525eb5210e3b8a3ec91 to your computer and use it in GitHub Desktop.

Select an option

Save blackhaj/1549791d63b5f525eb5210e3b8a3ec91 to your computer and use it in GitHub Desktop.
Gets all the people you follow on twitter
// Go to the list of people you follow e.g. https://twitter.com/HAJBlack/following
// (don't scroll, stay at the top of the page)
// Open the console and paste the code below
// copy the logged object and store it somewhere
const scrollToEndOfPage = () => {
window.scrollTo(0, document.body.scrollHeight);
};
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
const collateProfiles = () => {
const profiles = {};
for (let item of document.querySelectorAll('[data-testid="UserCell"]')) {
const link = item.getElementsByTagName('a');
const profileLink = link[0].href;
profiles[profileLink] = true;
}
return profiles;
};
const checkObjectSize = (profilesObject) => Object.keys(profilesObject).length;
const run = async () => {
let allProfiles = {};
let newProfilesAdded = true;
while (newProfilesAdded) {
newProfilesAdded = false;
let currentCount = checkObjectSize(allProfiles);
const newProfiles = collateProfiles();
allProfiles = Object.assign(allProfiles, newProfiles);
if (checkObjectSize(allProfiles) > currentCount) {
scrollToEndOfPage();
await delay(1000);
newProfilesAdded = true;
}
}
console.log(`Captured ${Object.keys(allProfiles).length}`);
console.log(allProfiles);
return allProfiles;
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment