Skip to content

Instantly share code, notes, and snippets.

@ejconlon
Created November 10, 2022 02:44
Show Gist options
  • Save ejconlon/97157bcca0e528f681de2d5087cf0394 to your computer and use it in GitHub Desktop.
Save ejconlon/97157bcca0e528f681de2d5087cf0394 to your computer and use it in GitHub Desktop.
// Go to twitter.com and paste this into the js console to block all verified users (slowly)
class CheckieBlock {
constructor() {
this.waitMs = 10*1000;
this.jitMs = 2*1000;
this.blockLimit = 1000;
this.seen = new Set();
}
sleep() {
const jit = Math.round(Math.random() * this.jitMs - this.jitMs / 2);
const ms = this.waitMs + jit;
return new Promise(resolve => setTimeout(resolve, ms));
}
async blockNext() {
const ns = document.getElementsByTagName('svg');
for (const n of ns) {
if (n && n.attributes && n.attributes['aria-label'] && n.attributes['aria-label'].value == 'Verified account') {
let x = n;
while (x && x.tagName != 'A') {
x = x.parentElement;
}
if (x) {
const addr = x.attributes['href'].value;
if (!this.seen.has(addr)) {
this.seen.add(addr);
x.click();
await this.sleep();
const moreOk = await this.openMore()
if (!moreOk) { return false; }
const askOk = await this.askBlock()
if (!askOk) { return false; }
const confirmOk = await this.confirmBlock()
if (!confirmOk) { return false; }
window.history.back()
await this.sleep();
return true;
}
}
}
}
return false;
}
async openMore() {
const ns = document.getElementsByTagName('div');
for (const n of ns) {
if (n && n.attributes && n.attributes['aria-label'] && n.attributes['aria-label'].value == 'More') {
n.click();
await this.sleep();
return true;
}
}
return false;
}
async askBlock() {
const ns = document.getElementsByTagName('div');
for (const n of ns) {
if (n && n.attributes && n.attributes['data-testid'] && n.attributes['data-testid'].value == 'block') {
n.click();
await this.sleep();
return true;
}
}
return false;
}
async confirmBlock() {
const ns = document.getElementsByTagName('div');
for (const n of ns) {
if (n && n.attributes && n.attributes['data-testid'] && n.attributes['data-testid'].value == 'confirmationSheetConfirm') {
n.click();
await this.sleep();
return true;
}
}
return false;
}
async blockAll() {
let lim = this.blockLimit;
while (lim > 0) {
const ok = await this.blockNext();
if (ok) {
lim--;
await this.sleep();
} else {
break;
}
}
return this.blockLimit - lim;
}
}
await new CheckieBlock().blockAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment