-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathunlikeAllPosts.js
More file actions
115 lines (94 loc) · 3.81 KB
/
Copy pathunlikeAllPosts.js
File metadata and controls
115 lines (94 loc) · 3.81 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
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/unlikeAllPosts.js
// Browser console script for unliking all your liked posts on X/Twitter
// Paste in DevTools console on x.com/YOUR_USERNAME/likes
// by nichxbt
(() => {
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
// =============================================
// CONFIGURATION
// =============================================
const CONFIG = {
maxUnlikes: 50,
skipKeywords: [], // Keep likes containing these words
dryRun: true, // Preview without unliking
delay: 1500,
scrollDelay: 2000,
maxEmptyScrolls: 6,
};
// =============================================
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 run = async () => {
console.log('💔 UNLIKE ALL POSTS — XActions by nichxbt');
console.log(CONFIG.dryRun ? '🔍 DRY RUN — preview only' : '⚠️ LIVE MODE — posts WILL be unliked!');
if (!window.location.href.includes('/likes')) {
console.error('❌ Navigate to x.com/YOUR_USERNAME/likes first!');
return;
}
console.log(`⚙️ Max: ${CONFIG.maxUnlikes} | Skip keywords: ${CONFIG.skipKeywords.length}`);
const unlikedLog = [];
let unliked = 0;
let skipped = 0;
let emptyScrolls = 0;
while (unliked < CONFIG.maxUnlikes && emptyScrolls < CONFIG.maxEmptyScrolls) {
const buttons = document.querySelectorAll('[data-testid="unlike"]');
if (buttons.length === 0) {
emptyScrolls++;
window.scrollTo(0, document.body.scrollHeight);
await sleep(CONFIG.scrollDelay);
continue;
}
emptyScrolls = 0;
for (const btn of buttons) {
if (unliked >= CONFIG.maxUnlikes) break;
const article = btn.closest('article');
const text = article?.querySelector('[data-testid="tweetText"]')?.textContent?.trim() || '';
const authorLink = article?.querySelector('a[href^="/"][role="link"]');
const author = authorLink?.getAttribute('href')?.replace('/', '') || 'unknown';
// Skip filter
if (CONFIG.skipKeywords.length > 0 && CONFIG.skipKeywords.some(kw => text.toLowerCase().includes(kw.toLowerCase()))) {
skipped++;
continue;
}
const preview = text.slice(0, 60).replace(/\n/g, ' ');
if (CONFIG.dryRun) {
console.log(`🔍 Would unlike: @${author} — "${preview}..."`);
unlikedLog.push({ author, text: text.slice(0, 200), dryRun: true });
unliked++;
continue;
}
try {
btn.click();
unliked++;
unlikedLog.push({ author, text: text.slice(0, 200), timestamp: new Date().toISOString() });
if (unliked % 10 === 0) console.log(`💔 Unliked ${unliked} posts...`);
await sleep(CONFIG.delay);
} catch (e) {
console.warn(`⚠️ Error unliking: ${e.message}`);
}
}
window.scrollTo(0, document.body.scrollHeight);
await sleep(CONFIG.scrollDelay);
}
console.log(`\n✅ Done! Unliked: ${unliked} | Skipped: ${skipped}`);
console.log(`🔍 Dry run: ${CONFIG.dryRun}`);
if (unlikedLog.length > 0) {
download(
{ stats: { unliked, skipped, dryRun: CONFIG.dryRun }, posts: unlikedLog },
`xactions-unliked-${new Date().toISOString().slice(0, 10)}.json`
);
}
if (CONFIG.dryRun && unliked > 0) {
console.log(`\n⚡ Set dryRun = false and re-run to actually unlike ${unliked} posts.`);
}
};
run();
})();