Skip to content

Instantly share code, notes, and snippets.

@insin
Created October 13, 2022 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insin/ebe2f8db377d8879935a32296330c6bb to your computer and use it in GitHub Desktop.
Save insin/ebe2f8db377d8879935a32296330c6bb to your computer and use it in GitHub Desktop.
Run this while viewing someone's Twitter /following list to get the handles of everyone they follow
let $follows = document.querySelector('div[data-testid="primaryColumn"] section > h1 + div[aria-label] > div')
let handles = new Set()
let finishTimeout
let observer
function finish() {
if (finishTimeout) {
clearTimeout(finishTimeout)
}
finishTimeout = setTimeout(() => {
console.log(Array.from(handles).join(', '))
observer.disconnect()
}, 10000)
}
function processFollows() {
for (let $follow of $follows.children) {
if ($follow.firstElementChild.style.display === 'none') {
continue
}
let $handle = $follow.querySelector('a:not([aria-hidden])[tabindex]')
if ($handle) {
handles.add($handle.innerText)
$follow.firstElementChild.style.display = 'none'
}
}
console.log(handles.size)
finish()
}
observer = new MutationObserver(processFollows)
observer.observe($follows, {childList: true})
processFollows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment