洛可可白:
(() => {
let key = '';
try {
key = JSON.parse(localStorage.getItem('security-sdk/s_sdk_cert_key') || '{}').data?.replace(/^pub\./, '') || '';
} catch { /* ignore */ }
let max_cursor = 0;
let total = 0;
let msgBox;
function showMsg(text) {
if (msgBox) document.body.removeChild(msgBox);
msgBox = document.createElement('div');
Object.assign(msgBox.style, {
position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%,-50%)',
padding: '12px 18px', background: '#3498db', color: '#fff',
borderRadius: '6px', zIndex: 9999, fontSize: '14px'
});
msgBox.textContent = text;
document.body.appendChild(msgBox);
}
// 串行取消点赞,1 秒一条
async function cancelList(ids) {
console.log(ids);
for (let i = 0; i < ids.length; i++) {
await cancelLike(ids[i]);
total++;
showMsg(`正在取消第 ${i + 1}/${ids.length} 个点赞,累计已取消 ${total} 个…`);
await sleep(500);
}
showMsg(`本批取消 ${ids.length} 个,总计已取消 ${total} 个,4 秒后继续拉取下一批。\n如想终止,直接关闭浏览器即可。`);
}
function sleep(ms) {
return new Promise(r => setTimeout(r, ms));
}
async function cancelLike(id) {
try {
await fetch('https://www.douyin.com/aweme/v1/web/commit/item/digg/?aid=6383', {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'bd-ticket-guard-ree-public-key': key
},
body: `aweme_id=${id}&item_type=0&type=0`,
credentials: 'include'
});
} catch { /* ignore network error */ }
}
async function fetchAndCancel() {
try {
const res = await fetch(`https://www.douyin.com/aweme/v1/web/aweme/favorite?aid=6383&count=999&max_cursor=${max_cursor}`, {
credentials: 'include'
});
const { aweme_list, max_cursor: next_cursor } = await res.json();
if (!Array.isArray(aweme_list) || aweme_list.length === 0) {
showMsg('已清空全部点赞,脚本结束。');
return;
}
max_cursor = next_cursor;
const ids = aweme_list.map(v => v.aweme_id);
await cancelList(ids);
} catch (e) {
console.error(e);
showMsg('拉取列表失败,稍候重试…');
}
}
setInterval(fetchAndCancel, 5000);
fetchAndCancel();
})();