Last active
April 21, 2023 22:34
-
-
Save adalinesimonian/e274b6333ed8cd31687f09e0da94050e to your computer and use it in GitHub Desktop.
Block all users in Twitter search results
This file contains hidden or 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
// 1. Search for the Twitter users you want to block. | |
// 2. Execute this script in your browser console. | |
// Only the accounts visible on the current page of results will be blocked. | |
// Scroll further down as the script runs to block more users. | |
// One-liner | |
(async () => { let element; while (element = document.querySelector('[role="article"] [aria-label="More"]')) { element.click(); await new Promise((resolve) => { const observer = new MutationObserver(() => { if (document.querySelector('[data-testid="block"]')) { observer.disconnect(); resolve(); } }); observer.observe(document.body, { childList: true, subtree: true }); }); document.querySelector('[data-testid="block"]').click(); await new Promise((resolve) => setTimeout(resolve, 500)); document.querySelector('[data-testid="confirmationSheetConfirm"]').click(); await new Promise((resolve) => setTimeout(resolve, 500)); } })(); | |
// Multi-line | |
;(async () => { | |
let element | |
while ( | |
(element = document.querySelector('[role="article"] [aria-label="More"]')) | |
) { | |
element.click() | |
await new Promise(resolve => { | |
const observer = new MutationObserver(() => { | |
if (document.querySelector('[data-testid="block"]')) { | |
observer.disconnect() | |
resolve() | |
} | |
}) | |
observer.observe(document.body, { childList: true, subtree: true }) | |
}) | |
document.querySelector('[data-testid="block"]').click() | |
await new Promise(resolve => setTimeout(resolve, 500)) | |
document.querySelector('[data-testid="confirmationSheetConfirm"]').click() | |
await new Promise(resolve => setTimeout(resolve, 500)) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment