-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathmassBlock.js
More file actions
189 lines (156 loc) · 6.33 KB
/
Copy pathmassBlock.js
File metadata and controls
189 lines (156 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/massBlock.js
// Browser console script for mass blocking users on X/Twitter
// Paste in DevTools console on x.com (followers, following, search, or any page with user cells)
// by nichxbt
(() => {
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
// =============================================
// CONFIGURATION
// =============================================
const CONFIG = {
mode: 'visible', // 'visible' = block users on page | 'list' = block by username
usersToBlock: [
// 'spammer1',
// 'spammer2',
],
whitelist: [], // Never block these (without @)
maxBlocks: 20, // Max users to block
dryRun: true, // SET FALSE TO EXECUTE
delay: 2000, // ms between blocks
scrollDelay: 2000, // ms to wait after scroll
maxEmptyScrolls: 5, // Give up after N scrolls with no new users
};
// =============================================
const download = (data, filename) => {
const a = document.createElement('a');
a.href = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }));
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
console.log(`📥 Downloaded: ${filename}`);
};
const whitelistSet = new Set(CONFIG.whitelist.map(u => u.toLowerCase().replace(/^@/, '')));
const processed = new Set();
const results = { blocked: [], skipped: [], failed: [] };
let blocked = 0;
const getUsername = (cell) => {
const link = cell.querySelector('a[href^="/"]');
if (!link) return null;
const match = (link.getAttribute('href') || '').match(/^\/([A-Za-z0-9_]+)/);
return match ? match[1] : null;
};
const blockVisibleUsers = async () => {
let emptyScrolls = 0;
while (blocked < CONFIG.maxBlocks && emptyScrolls < CONFIG.maxEmptyScrolls) {
const cells = document.querySelectorAll('[data-testid="UserCell"]');
let foundNew = false;
for (const cell of cells) {
if (blocked >= CONFIG.maxBlocks) break;
const username = getUsername(cell);
if (!username || processed.has(username.toLowerCase())) continue;
processed.add(username.toLowerCase());
foundNew = true;
if (whitelistSet.has(username.toLowerCase())) {
results.skipped.push(username);
console.log(`🛡️ Whitelisted: @${username}`);
continue;
}
if (CONFIG.dryRun) {
console.log(`🔍 Would block: @${username}`);
results.blocked.push({ username, dryRun: true });
blocked++;
continue;
}
const moreBtn = cell.querySelector('[data-testid="userActions"]');
if (!moreBtn) { results.failed.push(username); continue; }
moreBtn.click();
await sleep(800);
const menuItems = document.querySelectorAll('[role="menuitem"]');
let blockItem = null;
for (const item of menuItems) {
if (/\bblock\b/i.test(item.textContent)) { blockItem = item; break; }
}
if (!blockItem) { document.body.click(); await sleep(300); results.failed.push(username); continue; }
blockItem.click();
await sleep(600);
const confirmBtn = document.querySelector('[data-testid="confirmationSheetConfirm"]');
if (confirmBtn) {
confirmBtn.click();
await sleep(500);
blocked++;
results.blocked.push({ username, timestamp: new Date().toISOString() });
console.log(`🚫 Blocked @${username} [${blocked}/${CONFIG.maxBlocks}]`);
} else {
results.failed.push(username);
}
await sleep(CONFIG.delay);
}
if (!foundNew) emptyScrolls++; else emptyScrolls = 0;
window.scrollTo(0, document.body.scrollHeight);
await sleep(CONFIG.scrollDelay);
}
};
const blockByList = async () => {
if (CONFIG.usersToBlock.length === 0) {
console.error('❌ No users in CONFIG.usersToBlock!');
return;
}
for (const username of CONFIG.usersToBlock) {
if (blocked >= CONFIG.maxBlocks) break;
if (whitelistSet.has(username.toLowerCase())) {
results.skipped.push(username);
console.log(`🛡️ Whitelisted: @${username}`);
continue;
}
if (CONFIG.dryRun) {
console.log(`🔍 Would block: @${username}`);
results.blocked.push({ username, dryRun: true });
blocked++;
continue;
}
window.location.href = `https://x.com/${username}`;
await sleep(3500);
let attempts = 0;
while (!document.querySelector('[data-testid="userActions"]') && attempts < 10) {
await sleep(500);
attempts++;
}
const moreBtn = document.querySelector('[data-testid="userActions"]');
if (!moreBtn) { results.failed.push(username); continue; }
moreBtn.click();
await sleep(800);
const menuItems = document.querySelectorAll('[role="menuitem"]');
let blockItem = null;
for (const item of menuItems) {
if (/\bblock\b/i.test(item.textContent)) { blockItem = item; break; }
}
if (!blockItem) { document.body.click(); await sleep(300); results.skipped.push(username); continue; }
blockItem.click();
await sleep(600);
const confirmBtn = document.querySelector('[data-testid="confirmationSheetConfirm"]');
if (confirmBtn) {
confirmBtn.click();
await sleep(500);
blocked++;
results.blocked.push({ username, timestamp: new Date().toISOString() });
console.log(`🚫 Blocked @${username} [${blocked}/${CONFIG.maxBlocks}]`);
} else {
results.failed.push(username);
}
await sleep(CONFIG.delay);
}
};
const run = async () => {
console.log('🚫 MASS BLOCK — XActions by nichxbt');
console.log(`⚙️ Mode: ${CONFIG.mode} | Dry run: ${CONFIG.dryRun} | Max: ${CONFIG.maxBlocks}`);
if (CONFIG.mode === 'list') await blockByList();
else await blockVisibleUsers();
console.log(`\n✅ Done! Blocked: ${blocked} | Skipped: ${results.skipped.length} | Failed: ${results.failed.length}`);
if (results.blocked.length > 0) {
download(results, `xactions-blocked-${new Date().toISOString().slice(0, 10)}.json`);
}
};
run();
})();