-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathwelcomeNewFollowers.js
More file actions
169 lines (138 loc) · 6.35 KB
/
Copy pathwelcomeNewFollowers.js
File metadata and controls
169 lines (138 loc) · 6.35 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
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/welcomeNewFollowers.js
// Browser console script for welcoming new followers with DMs on X/Twitter
// Paste in DevTools console on x.com/USERNAME/followers
// by nichxbt
(() => {
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
// =============================================
// CONFIGURATION
// =============================================
const CONFIG = {
messageTemplates: [
"Hey @{username}! 👋 Thanks for the follow! Glad to have you here.",
"Welcome @{username}! 🙌 Thanks for connecting. Feel free to reach out anytime!",
"Hey there @{username}! Thanks for the follow! Hope you find the content valuable. 🚀",
],
maxDMs: 10, // Max DMs to send per run
dryRun: true, // Preview without sending — SET FALSE TO SEND
dmDelay: 60000, // 60s between DMs (conservative to avoid rate limits)
maxFollowers: 200, // Max followers to scan
scrollDelay: 2000, // ms between scrolls
scrollRounds: 5, // Number of scroll rounds
exportOnComplete: true,
};
// =============================================
const STORAGE_KEY = 'xactions_known_followers';
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 getKnown = () => {
try { return new Set(JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')); }
catch { return new Set(); }
};
const saveKnown = (set) => {
localStorage.setItem(STORAGE_KEY, JSON.stringify([...set]));
};
const fillMessage = (template, username, displayName) => {
return template
.replace(/\{username\}/g, username)
.replace(/\{displayName\}/g, displayName || username);
};
const run = async () => {
console.log('👋 WELCOME NEW FOLLOWERS — by nichxbt');
if (!window.location.href.includes('/followers')) {
console.error('❌ Navigate to x.com/YOUR_USERNAME/followers first!');
return;
}
const knownBefore = getKnown();
const isFirstRun = knownBefore.size === 0;
console.log(`\n📋 Known followers: ${knownBefore.size}${isFirstRun ? ' (first run — will baseline)' : ''}`);
console.log(`⚙️ Dry run: ${CONFIG.dryRun} | Max DMs: ${CONFIG.maxDMs}\n`);
// Collect current followers
const followers = new Map();
for (let round = 0; round < CONFIG.scrollRounds && followers.size < CONFIG.maxFollowers; round++) {
for (const cell of document.querySelectorAll('[data-testid="UserCell"]')) {
const link = cell.querySelector('a[href^="/"][role="link"]') || cell.querySelector('a[href^="/"]');
if (!link) continue;
const m = (link.getAttribute('href') || '').match(/^\/([A-Za-z0-9_]+)/);
if (!m || ['home', 'explore', 'notifications', 'messages', 'i'].includes(m[1])) continue;
const username = m[1];
if (followers.has(username.toLowerCase())) continue;
const nameEl = cell.querySelector('a[href^="/"] span');
const displayName = nameEl ? nameEl.textContent.trim() : username;
followers.set(username.toLowerCase(), { username, displayName });
}
console.log(` 📜 Round ${round + 1}: ${followers.size} followers collected`);
window.scrollTo(0, document.body.scrollHeight);
await sleep(CONFIG.scrollDelay);
}
console.log(`\n📊 Total collected: ${followers.size}`);
// Detect new followers
const newFollowers = [];
for (const [key, data] of followers) {
if (!knownBefore.has(key)) newFollowers.push(data);
}
// Update known list
const updatedKnown = new Set([...knownBefore, ...followers.keys()]);
saveKnown(updatedKnown);
if (isFirstRun) {
console.log(`\n✅ First run! Baselined ${followers.size} followers.`);
console.log(' Run again later to detect NEW followers and send welcome DMs.');
return;
}
console.log(`\n🆕 New followers: ${newFollowers.length}`);
if (newFollowers.length === 0) {
console.log(' No new followers since last run.\n');
return;
}
// Show new followers
console.log('\n New followers:');
for (const f of newFollowers) {
console.log(` 👤 @${f.username} (${f.displayName})`);
}
// DM logic
let dmsSent = 0;
if (!CONFIG.dryRun && CONFIG.messageTemplates.length > 0) {
console.log(`\n📬 Sending welcome DMs (max ${CONFIG.maxDMs})...`);
console.log('⚠️ NOTE: Mass DMing may violate X ToS. Use responsibly.\n');
for (const follower of newFollowers.slice(0, CONFIG.maxDMs)) {
const template = CONFIG.messageTemplates[Math.floor(Math.random() * CONFIG.messageTemplates.length)];
const message = fillMessage(template, follower.username, follower.displayName);
// Navigate to DM compose
// NOTE: Actual DM sending requires navigating to messages page.
// This logs the intent — full automation would need page navigation.
console.log(` 📨 @${follower.username}: "${message}"`);
console.log(` ⏳ Waiting ${CONFIG.dmDelay / 1000}s...`);
dmsSent++;
await sleep(CONFIG.dmDelay);
}
} else if (CONFIG.dryRun) {
console.log('\n📬 Messages that would be sent (DRY RUN):');
for (const follower of newFollowers.slice(0, CONFIG.maxDMs)) {
const template = CONFIG.messageTemplates[Math.floor(Math.random() * CONFIG.messageTemplates.length)];
const message = fillMessage(template, follower.username, follower.displayName);
console.log(` 📨 @${follower.username}: "${message}"`);
}
}
// Summary
console.log('\n📊 RESULTS');
console.log(` New followers: ${newFollowers.length}`);
console.log(` DMs sent: ${dmsSent}`);
console.log(` Total known: ${updatedKnown.size}`);
if (CONFIG.exportOnComplete && newFollowers.length > 0) {
download(
{ newFollowers, dmsSent, totalKnown: updatedKnown.size, detectedAt: new Date().toISOString() },
`xactions-new-followers-${new Date().toISOString().slice(0, 10)}.json`
);
}
console.log('✅ Done!\n');
};
run();
})();