-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathquoteTweetAutomation.js
More file actions
183 lines (149 loc) · 7.07 KB
/
Copy pathquoteTweetAutomation.js
File metadata and controls
183 lines (149 loc) · 7.07 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
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/quoteTweetAutomation.js
// Browser console script for auto quote-tweeting matching tweets with templates
// Paste in DevTools console on x.com/home or any timeline/search
// by nichxbt
(() => {
'use strict';
// ── CONFIG ────────────────────────────────────────────────
const CONFIG = {
maxQuotes: 5,
dryRun: true,
templates: [
'Great thread! 🧵',
'Interesting perspective 🤔',
'💯 This is so underrated.',
'📌 Saving this — great insight.',
],
onlyKeywords: [], // tweet must contain one (empty = any)
skipKeywords: ['ad', 'promoted', 'giveaway', 'dm me'],
delay: 5000,
scrollRounds: 3,
scrollDelay: 2000,
};
// ── HELPERS ───────────────────────────────────────────────
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
const rand = (a, b) => Math.floor(a + Math.random() * (b - a));
const parseCount = (str) => {
if (!str) return 0;
str = str.replace(/,/g, '').trim();
const m = str.match(/([\d.]+)([KMB])?/i);
if (!m) return 0;
let n = parseFloat(m[1]);
if (m[2]) n *= { K: 1e3, M: 1e6, B: 1e9 }[m[2].toUpperCase()];
return Math.round(n);
};
// ── COLLECT TARGETS ───────────────────────────────────────
const collectTargets = async () => {
const targets = [];
const seen = new Set();
for (let round = 0; round < CONFIG.scrollRounds; round++) {
const articles = document.querySelectorAll('article[data-testid="tweet"]');
for (const article of articles) {
const textEl = article.querySelector('[data-testid="tweetText"]');
const text = textEl?.textContent?.trim() || '';
if (!text) continue;
const fp = text.slice(0, 80);
if (seen.has(fp)) continue;
seen.add(fp);
const lower = text.toLowerCase();
if (CONFIG.skipKeywords.some(kw => lower.includes(kw.toLowerCase()))) continue;
if (CONFIG.onlyKeywords.length > 0 && !CONFIG.onlyKeywords.some(kw => lower.includes(kw.toLowerCase()))) continue;
// Skip already retweeted
if (article.querySelector('[data-testid="unretweet"]')) continue;
const authorEl = article.querySelector('a[href^="/"][role="link"] span');
const author = authorEl?.textContent?.trim() || 'unknown';
targets.push({ article, text, author });
}
console.log(` 📜 Round ${round + 1}: ${targets.length} eligible tweets`);
window.scrollTo(0, document.body.scrollHeight);
await sleep(CONFIG.scrollDelay);
}
return targets;
};
// ── QUOTE SINGLE TWEET ────────────────────────────────────
const quoteTweet = async (target, template) => {
const { article, author } = target;
article.scrollIntoView({ behavior: 'smooth', block: 'center' });
await sleep(1000);
// Click retweet to open menu
const rtBtn = article.querySelector('[data-testid="retweet"]');
if (!rtBtn) { console.log(' ⚠️ No retweet button'); return false; }
rtBtn.click();
await sleep(800);
// Find "Quote" option in dropdown
let quoteOpt = null;
for (const el of document.querySelectorAll('[role="menuitem"]')) {
if ((el.textContent || '').toLowerCase().includes('quote')) { quoteOpt = el; break; }
}
if (!quoteOpt) {
console.log(' ⚠️ "Quote" option not found');
document.body.click();
await sleep(300);
return false;
}
quoteOpt.click();
await sleep(1500);
// Type quote text
const tweetBox = document.querySelector('[data-testid="tweetTextarea_0"]');
if (!tweetBox) { console.log(' ⚠️ Compose box not found'); return false; }
const quoteText = template.replace('{author}', author);
tweetBox.focus();
for (const ch of quoteText) {
document.execCommand('insertText', false, ch);
await sleep(rand(30, 80));
}
await sleep(600);
if (CONFIG.dryRun) {
console.log(` 🏃 DRY RUN — would post: "${quoteText}"`);
const closeBtn = document.querySelector('[data-testid="app-bar-close"]') || document.querySelector('[aria-label="Close"]');
if (closeBtn) closeBtn.click();
await sleep(500);
const discardBtn = document.querySelector('[data-testid="confirmationSheetConfirm"]');
if (discardBtn) { discardBtn.click(); await sleep(300); }
return true;
}
const sendBtn = document.querySelector('[data-testid="tweetButton"]');
if (!sendBtn) { console.log(' ⚠️ Tweet button not found'); return false; }
sendBtn.click();
await sleep(2000);
return true;
};
// ── MAIN ──────────────────────────────────────────────────
(async () => {
console.log('🔁 QUOTE TWEET AUTOMATION — XActions by nichxbt');
console.log(` Mode: ${CONFIG.dryRun ? '🔍 DRY RUN' : '⚡ LIVE'} | Max: ${CONFIG.maxQuotes}\n`);
console.log('🔍 Collecting target tweets...\n');
const targets = await collectTargets();
if (targets.length === 0) {
console.error('❌ No eligible tweets found. Adjust keywords or scroll more.');
return;
}
const toProcess = targets.slice(0, CONFIG.maxQuotes);
console.log(`\n📊 Found ${targets.length} eligible. Processing ${toProcess.length}.\n`);
let success = 0;
let fail = 0;
for (let i = 0; i < toProcess.length; i++) {
const target = toProcess[i];
const template = CONFIG.templates[i % CONFIG.templates.length];
console.log(`[${i + 1}/${toProcess.length}] 🔁 Quote-tweeting "${target.text.slice(0, 50)}..." (by ${target.author})`);
const ok = await quoteTweet(target, template);
if (ok) success++;
else fail++;
if (i < toProcess.length - 1) {
const wait = CONFIG.delay + rand(0, 2000);
console.log(` ⏳ Waiting ${(wait / 1000).toFixed(0)}s...`);
await sleep(wait);
}
}
// ── SUMMARY ─────────────────────────────────────────────
console.log('\n╔══════════════════════════════════════╗');
console.log('║ ✅ QUOTE TWEET COMPLETE ║');
console.log('╚══════════════════════════════════════╝');
console.log(` ✅ Quoted: ${success} | ❌ Failed: ${fail}`);
if (CONFIG.dryRun) console.log(' 🏃 (Dry run — nothing was posted)');
if (CONFIG.dryRun && success > 0) {
console.log(`\n ⚡ Set dryRun = false to post ${success} quotes for real.\n`);
}
})();
})();