Last active
April 8, 2024 01:15
-
-
Save JimLiu/ffb1de258d02d7f67d51fbffa28b7854 to your computer and use it in GitHub Desktop.
微博一键拉黑点赞
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 使用方法: | |
// 1. Chrome打开weibo.com | |
// 2. 打开Chrome Dev Tool(使用 Ctrl/Cmd + Shift + I) | |
// 3. 在Console中复制粘贴以下代码,修改评论id为你要一键拉黑的评论ID | |
// 4. 回车运行 | |
// 获取评论id方法: | |
// 1. 在评论下点击投诉,在新窗口中可以得到评论id,例如 https://service.account.weibo.com/reportspam?rid=XXXXXXXXXX | |
const cId = 123456 // 修改为真实评论ID | |
await blockByComment(cId); | |
async function blockByComment(commentId) { | |
function getCookieValueByName(name) { | |
var match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)")); | |
return match ? match[2] : ""; | |
} | |
async function getLikedUserIds(commentId) { | |
const userIds = []; | |
let pageNumber = 1; | |
while (true) { | |
var url = `/aj/like/object/big?ajwvr=6&page=${pageNumber}&object_id=${commentId}&object_type=comment`; | |
const res = await fetch(url, { | |
mode: "cors", | |
credentials: "include", | |
}); | |
const json = await res.json(); | |
const { data, code } = json; | |
if (code != 100000) { | |
console.log("error", json); | |
break; | |
} | |
let temp = data.html.match(/(?:uid=\")(\d+)(?:\")/g); | |
if (temp) { | |
for (let i = 0; i < temp.length; i++) { | |
userIds.push(temp[i].match(/\d{10}/i)[0]); | |
} | |
} | |
if (data.page.pagenum == data.page.totalpage) { | |
break; | |
} | |
pageNumber++; | |
} | |
return userIds.map((id) => parseInt(id)); | |
} | |
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
const failedUserIds = []; | |
async function blockByUserIds(userIds) { | |
for (let userId of userIds) { | |
console.log("start to block", `https://m.weibo.cn/profile/${userId}`); | |
try { | |
const xsrf = getCookieValueByName("XSRF-TOKEN"); | |
await fetch("/ajax/statuses/filterUser", { | |
headers: { | |
"content-type": "application/json;charset=UTF-8", | |
"x-xsrf-token": xsrf, | |
}, | |
body: JSON.stringify({ | |
uid: userId, | |
status: 1, | |
interact: 1, | |
follow: 1, | |
}), | |
method: "POST", | |
mode: "cors", | |
credentials: "include", | |
}); | |
console.log("block success", userId); | |
console.log("wait 1s"); | |
await delay(1000); | |
} catch (e) { | |
console.log("block failed", userId); | |
console.log("wait 1s"); | |
failedUserIds = [...failedUserIds, userId]; | |
await delay(1000); | |
} | |
} | |
} | |
const userIds = await getLikedUserIds(commentId); | |
console.log('userIds', userIds); | |
await blockByUserIds(userIds); | |
console.log('retry failedUserIds', failedUserIds); | |
const clonedFailedUserIds = [...failedUserIds]; | |
failedUserIds.length = 0; | |
await blockByUserIds(clonedFailedUserIds); | |
console.log('retry done'); | |
console.log('Failed UserIds', failedUserIds) | |
console.log('done'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment