-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathlistManager.js
More file actions
171 lines (139 loc) · 5.47 KB
/
Copy pathlistManager.js
File metadata and controls
171 lines (139 loc) · 5.47 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
// Copyright (c) 2024-2026 nich (@nichxbt). Licensed under the Apache License, Version 2.0.
// scripts/listManager.js
// Browser console script for creating and managing X/Twitter lists
// Paste in DevTools console on x.com/i/lists
// by nichxbt
(() => {
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
// =============================================
// CONFIGURATION
// =============================================
const CONFIG = {
action: 'create', // 'create' | 'addMembers' | 'exportMembers'
listName: 'My List',
listDescription: 'Created by XActions',
isPrivate: false,
usernames: [
// 'user1',
// 'user2',
],
maxMembers: 200, // For export
dryRun: true, // SET FALSE TO EXECUTE
delay: 2000,
scrollDelay: 1500,
};
// =============================================
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 createList = async () => {
console.log(`📋 Creating list: "${CONFIG.listName}"`);
if (CONFIG.dryRun) {
console.log(` 📝 Would create list: "${CONFIG.listName}" (${CONFIG.isPrivate ? 'private' : 'public'})`);
return;
}
const createBtn = document.querySelector('[data-testid="createList"]');
if (createBtn) { createBtn.click(); await sleep(1500); }
const nameInput = document.querySelector('[data-testid="listNameInput"]');
if (nameInput) {
nameInput.focus();
document.execCommand('insertText', false, CONFIG.listName);
await sleep(500);
}
const descInput = document.querySelector('[data-testid="listDescriptionInput"]');
if (descInput && CONFIG.listDescription) {
descInput.focus();
document.execCommand('insertText', false, CONFIG.listDescription);
await sleep(500);
}
if (CONFIG.isPrivate) {
const toggle = document.querySelector('[data-testid="listPrivateToggle"]');
if (toggle) toggle.click();
await sleep(300);
}
const saveBtn = document.querySelector('[data-testid="listSaveButton"]');
if (saveBtn) { saveBtn.click(); await sleep(1500); }
console.log('✅ List created!');
};
const addMembers = async () => {
const users = CONFIG.usernames;
if (users.length === 0) {
console.error('❌ No usernames provided! Edit CONFIG.usernames.');
return;
}
console.log(`👥 Adding ${users.length} users to list...`);
if (CONFIG.dryRun) {
users.forEach(u => console.log(` 📝 Would add: @${u}`));
return;
}
const addBtn = document.querySelector('[data-testid="addMembers"]');
if (addBtn) { addBtn.click(); await sleep(1500); }
let added = 0;
for (const username of users) {
const searchInput = document.querySelector('[data-testid="searchPeople"]');
if (!searchInput) { console.error('❌ Search input not found'); break; }
searchInput.focus();
searchInput.value = '';
document.execCommand('insertText', false, username);
await sleep(2000);
const cells = document.querySelectorAll('[data-testid="UserCell"]');
let found = false;
for (const cell of cells) {
if (cell.textContent.toLowerCase().includes(username.toLowerCase())) {
cell.click();
found = true;
added++;
console.log(` ✅ Added @${username}`);
break;
}
}
if (!found) console.warn(` ⚠️ @${username} not found`);
searchInput.value = '';
searchInput.dispatchEvent(new Event('input', { bubbles: true }));
await sleep(CONFIG.delay);
}
console.log(`✅ Added ${added}/${users.length} members`);
};
const exportMembers = async () => {
console.log('📥 Exporting list members...');
const members = new Map();
let retries = 0;
while (members.size < CONFIG.maxMembers && retries < 5) {
const prevSize = members.size;
document.querySelectorAll('[data-testid="UserCell"]').forEach(cell => {
const linkEl = cell.querySelector('a[href^="/"]');
const username = linkEl?.href?.replace(/^.*x\.com\//, '').split('/')[0] || '';
if (!username || members.has(username)) return;
const nameEl = cell.querySelector('[data-testid="User-Name"]');
const bioEl = cell.querySelector('[dir="auto"]:not([data-testid])');
members.set(username, {
username,
displayName: nameEl?.textContent?.split('@')[0]?.trim() || '',
bio: bioEl?.textContent || '',
});
});
if (members.size === prevSize) retries++;
else retries = 0;
window.scrollTo(0, document.body.scrollHeight);
await sleep(CONFIG.scrollDelay);
}
const data = [...members.values()];
download(data, `xactions-list-members-${new Date().toISOString().slice(0, 10)}.json`);
console.log(`✅ Exported ${data.length} members`);
};
const run = async () => {
console.log('📋 LIST MANAGER — XActions by nichxbt\n');
if (CONFIG.action === 'create') await createList();
else if (CONFIG.action === 'addMembers') await addMembers();
else if (CONFIG.action === 'exportMembers') await exportMembers();
else console.error(`❌ Unknown action: ${CONFIG.action}`);
console.log('\n🏁 Done!');
};
run();
})();