-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathmanageLists.js
More file actions
113 lines (90 loc) · 3.6 KB
/
Copy pathmanageLists.js
File metadata and controls
113 lines (90 loc) · 3.6 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
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/manageLists.js
// Browser console script to manage X/Twitter Lists
// Paste in DevTools console on x.com/i/lists
// by nichxbt
(() => {
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
const extractBio = (cell) => {
const testId = cell.querySelector('[data-testid="UserDescription"]');
if (testId?.textContent?.trim()) return testId.textContent.trim();
const autoDir = cell.querySelector('[dir="auto"]:not([data-testid])');
const text = autoDir?.textContent?.trim();
if (text && text.length >= 10 && !text.startsWith('@')) return text;
return '';
};
const CONFIG = {
action: 'export', // 'export' or 'export_members'
maxLists: 50,
maxMembers: 100,
};
const exportLists = async () => {
console.log('📋 Exporting lists...');
const lists = [];
let scrollAttempts = 0;
while (lists.length < CONFIG.maxLists && scrollAttempts < 10) {
document.querySelectorAll('[data-testid="listItem"], a[href*="/lists/"]').forEach(el => {
const name = el.querySelector('[dir="ltr"]')?.textContent || el.textContent?.trim() || '';
const link = el.href || el.querySelector('a')?.href || '';
const description = el.querySelector('[data-testid="listDescription"]')?.textContent || '';
const memberCount = el.querySelector('[data-testid="memberCount"]')?.textContent || '';
if (name && link && !lists.find(l => l.link === link)) {
lists.push({
name: name.trim().substring(0, 100),
link,
description: description.trim(),
memberCount,
});
}
});
window.scrollBy(0, 800);
await sleep(1500);
scrollAttempts++;
}
console.log(` Found ${lists.length} lists`);
lists.forEach((l, i) => {
console.log(` ${i + 1}. ${l.name} ${l.memberCount ? `(${l.memberCount} members)` : ''}`);
});
return lists;
};
const exportListMembers = async () => {
console.log('👥 Exporting list members from current list...');
console.log(' (Navigate to a specific list first)');
const members = [];
let scrollAttempts = 0;
while (members.length < CONFIG.maxMembers && scrollAttempts < Math.ceil(CONFIG.maxMembers / 5)) {
document.querySelectorAll('[data-testid="UserCell"]').forEach(user => {
const name = user.querySelector('[dir="ltr"]')?.textContent || '';
const handle = user.querySelector('a[role="link"]')?.href?.split('/').pop() || '';
const bio = extractBio(user);
const isVerified = !!user.querySelector('[data-testid="icon-verified"]');
if (handle && !members.find(m => m.handle === handle)) {
members.push({ name: name.trim(), handle, bio: bio.trim().substring(0, 200), isVerified });
}
});
window.scrollBy(0, 800);
await sleep(1500);
scrollAttempts++;
}
console.log(` Found ${members.length} members`);
return members;
};
const run = async () => {
console.log('📋 XActions List Manager');
console.log('========================');
let result = {};
if (CONFIG.action === 'export_members') {
result.members = await exportListMembers();
} else {
result.lists = await exportLists();
}
result.scrapedAt = new Date().toISOString();
console.log('\n📦 Full JSON:');
console.log(JSON.stringify(result, null, 2));
try {
await navigator.clipboard.writeText(JSON.stringify(result, null, 2));
console.log('\n✅ Copied to clipboard!');
} catch (e) {}
};
run();
})();