关于在推特上如何批量取消关注
不知道什么时候很少用的推特居然关注了 3000 多人, 导致想要的消息都淹没在数字垃圾中. 今天随便搜一下就找到了解决办法[1], 具体步骤如下:
首先用电脑的浏览器打开你的推特账号的关注页面 https://twitter.com/你的账号/following, 注意要先登录.
打开 https://pastebin.com/raw/0VuPT26E 全选并复制显示的脚本 (ctrl + A, ctrl + C), 你也可以复制一下代码, 一样的
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(() => {
const $followButtons = '[data-testid$="-unfollow"]';
const $confirmButton = '[data-testid="confirmationSheetConfirm"]';
const retry = {
count: 0,
limit: 10,// 重试次数
};
const scrollToTheBottom = () => window.scrollTo(0, document.body.scrollHeight);
const retryLimitReached = () => retry.count === retry.limit;
const addNewRetry = () => retry.count++;
const sleep = ({ seconds }) =>
new Promise((proceed) => {
console.log(`WAITING FOR ${seconds} SECONDS...`);
setTimeout(proceed, seconds * 1000);
});
const unfollowAll = async (followButtons) => {
console.log(`UNFOLLOWING ${followButtons.length} USERS...`);
await Promise.all(
followButtons.map(async (followButton) => {
followButton && followButton.click();
await sleep({ seconds: 1 });
const confirmButton = document.querySelector($confirmButton);
confirmButton && confirmButton.click();
})
);
};
const nextBatch = async () => {
scrollToTheBottom();
await sleep({ seconds: 2 });
const followButtons = Array.from(document.querySelectorAll($followButtons));
const followButtonsWereFound = followButtons.length > 0;
if (followButtonsWereFound) {
await unfollowAll(followButtons);
await sleep({ seconds: 2 });
return nextBatch();
} else {
addNewRetry();
}
if (retryLimitReached()) {
console.log(`NO ACCOUNTS FOUND, SO I THINK WE'RE DONE`);
console.log(`RELOAD PAGE AND RE-RUN SCRIPT IF ANY WERE MISSED`);
} else {
await sleep({ seconds: 2 });
return nextBatch();
}
};
nextBatch();
})();注意, 这里面的重试次数和后面几个延时参数可以根据自己的实际情况调整
回到推特的关注页面, 按 f12, 把刚才复制的代码粘贴到控制台中, 按回车运行.
等待运行结束, 由于网络等其他因素的影响可能会导致脚本误判已经清完了, 而实际还有关注, 这时刷新一下页面在重新执行 3 步骤即可.