-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ce-Mei-Killer.js
224 lines (192 loc) · 6.63 KB
/
Ce-Mei-Killer.js
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// 通用的网络请求函数
async function makeRequest(url, method = 'GET', body = null, headers = {}) {
try {
const response = await fetch(url, {
method,
headers,
body
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Request failed:', error);
}
}
// 获取总页数
async function getTotalPages(uid, pageSize) {
const url = `https://weibo.com/ajax/user/popcard/get?id=${uid}`;
const data = await makeRequest(url);
if (data) {
console.log(data);
const followersCount = parseInt(data.data.followers_count_str, 10);
return Math.ceil(followersCount / pageSize);
}
return 0;
}
// 获取某一页的粉丝
async function fetchPage(uid, page) {
const url = `https://weibo.com/ajax/friendships/friends?relate=fans&page=${page}&uid=${uid}&type=fans&newFollowerCount=0`;
const data = await makeRequest(url);
if (data && data.users && data.users.length > 0) {
console.log(`Fetched page ${page}.`);
return data.users;
} else {
console.log(`Page ${page} is empty, possibly blocked dogs.`);
return [];
}
}
// 获取某一页的粉丝, 前5000接口
async function fetchPage5000(uid, page) {
const since = page*20;
const url = `https://m.weibo.cn/api/container/getIndex?containerid=231051_-_fans_-_${uid}&since_id=${since}`;
const data = await makeRequest(url);
if (data && data?.data?.cards && data.data.cards.length > 0) {
console.log(`Fetched page ${page}.`);
return data.data.cards.map(e=>e.card_group).flat().filter(e=>e.buttons).map(e=>e.buttons).flat().map(e=>e.params.uid)
} else {
console.log(`Page ${page} is empty, possibly blocked dogs.`);
return [];
}
}
// 获取所有粉丝的封装函数
async function fetchAllFans(uid) {
const pageSize = 20;
const totalPages = await getTotalPages(uid, pageSize);
console.log(`------- Fetching ${totalPages} pages of dogs -------`);
if (totalPages === 0) {
console.log('No pages to fetch or error occurred.');
return [];
}
let allFans = [];
for (let page = 0; page <= totalPages; page++) {
const fans = await fetchPage(uid, page);
allFans = allFans.concat(fans);
delay(500)//避免渣浪制裁
}
allFans = allFans.map(e=>e.id)
allFans.push(uid);
console.log('All dogs fetched. Total dogs:', allFans.length);
console.log(allFans)
return allFans;
}
async function fetch5000Fans(uid) {
const pageSize = 20;
const totalPages =250;
console.log(`------- Fetching first 5000 dogs, perhaps 250 pages -------`);
if (totalPages === 0) {
console.log('No pages to fetch or error occurred.');
return [];
}
let allFans = [];
for (let page = 0; page <= totalPages; page++) {
const fans = await fetchPage5000(uid, page);
allFans = allFans.concat(fans);
delay(200)//避免渣浪制裁
}
allFans.push(uid);
console.log('first 5000 dogs fetched. Total dogs:', allFans.length);
console.log(allFans)
return allFans;
}
// 拉黑某个用户
async function blockDog(userId) {
console.log("开始拉黑")
console.log(userId)
var url = 'https://weibo.com/aj/filter/block?ajwvr=6';
var body = `uid=${userId}&filter_type=1&status=1&interact=1&follow=1`;
var headers = {
'Content-type': 'application/x-www-form-urlencoded'
};
const data = await makeRequest(url, 'POST', body, headers);
if (data && data.code == 100000) {
console.log(`[${userId}] => Block success: ${data.msg}`);
} else {
console.error(`[${userId}] => Block failed: ${data.msg}`);
}
}
// 拉黑所有粉丝
async function blockAllDogs(uid) {
window.allDogs = await fetchAllFans(uid);
mainBlockList(window.allDogs);
}
async function block5000Dogs(uid) {
window.allDogs = await fetch5000Fans(uid);
mainBlockList(window.allDogs);
}
// 主函数 - 一键拉黑版本
async function mainBlockAll(uid) {
try {
await blockAllDogs(uid);
} catch (error) {
console.error('An error occurred in mainBlockAll:', error);
}
}
// 主函数 - 拉黑前5000版本
async function mainBlock5000(uid) {
try {
await block5000Dogs(uid);
} catch (error) {
console.error('An error occurred in mainBlockAll:', error);
}
}
// 主函数 - 只获取厕所账号粉丝版本
async function mainFetchFans(uid) {
try {
await fetchAllFans(uid);
} catch (error) {
console.error('An error occurred in mainFetchFans:', error);
}
}
// 主函数 - 获取红v厕所前5000粉丝
async function mainFetchFans5000(uid) {
try {
await fetch5000Fans(uid);
} catch (error) {
console.error('An error occurred in mainFetchFans:', error);
}
}
// 暴力法延迟
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// 主函数 - 只拉黑一个uid数组版本
async function mainBlockList(uids) {
if (typeof window.allDogs == 'undefined') window.allDogs = uids;
try {
for (let index = 0; index < uids.length; index++) {
const userId = uids[index];
console.log(`Blocking dog ${userId} at index ${index} total ${uids.length}`); // 输出当前userId和下标
await blockDog(userId); // 执行拉黑操作
await delay(400); // 等待0.4秒
}
} catch (error) {
console.error('An error occurred in mainBlockList:', error);
}
}
// 主函数 - 从上一次失败处重新kill
async function mainResume(uid) {
try {
const dogs = window.allDogs || [];
const index = dogs.indexOf(uid);
if (index === -1) {
console.log('UID not found in allDogs.');
return;
}
const dogsToBlock = dogs.slice(index); // 从指定的UID开始到数组末尾的所有dogs
console.log("继续拉黑")
console.log(dogsToBlock)
mainBlockList(dogsToBlock); // 开始拉黑操作
} catch (error) {
console.error('An error occurred:', error);
}
}
// 根据需要调用不同的主函数
//mainBlockAll(2303645815); // 替换为目标用户ID,一键拉黑
//mainBlock5000(2303645815); // 替换为目标用户ID,获取红v厕所前5000粉丝,一键拉黑,目前还有问题(跨域)
///mainFetchFans5000(2303645815) // 获取红v厕所前5000粉丝
// mainFetchFans(2303645815);//只获取厕所粉丝
// mainFetchFans(2303645815); // 替换为目标用户ID,只获取厕所账号粉丝
// mainBlockList([12345, 67890]); // 替换为需要拉黑的用户ID数组,只拉黑指定用户
//mainResume(12345)//从上一次失败处开始拉黑,用于请求太频繁被大眼制裁的情况