🌟 前言

欢迎来到我的技术小宇宙!🌌 这里不仅是我记录技术点滴的后花园,也是我分享学习心得和项目经验的乐园。📚 无论你是技术小白还是资深大牛,这里总有一些内容能触动你的好奇心。🔍

Alt

脚本功能

这个脚本通过定期发送请求到抖音的服务器,获取用户点赞的视频列表,并批量发送取消点赞的请求。它还提供了一个消息框,实时显示取消点赞的进度和总数。

技术实现

脚本主要使用了JavaScript的fetch API来与抖音的服务器进行交互,同时利用了localStorage来存储和获取密钥。通过Promise.all实现了并发请求,提高了取消点赞的效率。此外,使用setInterval函数每隔4秒自动执行一次取消点赞的操作。

脚本代码

// 从localStorage中获取密钥,并去除前缀'pub.'(如果存在)
let key = JSON.parse(localStorage.getItem('security-sdk/s_sdk_cert_key')).data.replace(/^pub\./, '');
let max_cursorTemp = 0; // 用于存储最大的游标值
let messageBox = undefined; // 用于存储消息框的DOM元素

var count = 0; // 用于统计总共取消了多少个点赞

// 异步函数,用于获取点赞列表并批量取消点赞
async function fetchAndCancelLikes(maxCursor = max_cursorTemp) {
    try {
        // 发送GET请求到抖音的接口,获取点赞列表
        const response = await fetch(`https://www.douyin.com/aweme/v1/web/aweme/favorite?aid=6383&count=999&max_cursor=${max_cursorTemp}`,  {
            "referrerPolicy": "strict-origin-when-cross-origin",
            "body": null,
            "method": "GET",
            "mode": "cors",
            "credentials": "include"
        });
        const { aweme_list, max_cursor } = await response.json();
        max_cursorTemp = max_cursor; // 更新最大游标值

        // 如果响应中包含aweme_list,则提取出所有的aweme_id
        if (aweme_list != null) {
            const idsToCancel = aweme_list.map(({ aweme_id }) => aweme_id);
            let currCount = 0;
            // 使用Promise.all并发取消所有的点赞
            await Promise.all(idsToCancel.map(id => {
                cancelLike(id, key);
                currCount++;
                count++;
            })).then(()=>{
                // 取消点赞后,更新消息框
                if(messageBox!=undefined){
                    document.body.removeChild(messageBox);
                }
                messageBox = showMessageBox(`本次执行取消${currCount}个点赞,共取消${count}个点赞,四秒后继续执行,如果不需要执行直接关闭浏览器,当前时间${new Date()}`);
            });
        }

    } catch (error) {
        // 如果请求失败,捕获错误并打印到控制台
        console.error('Error fetching and canceling likes:', error);
    }
}

// 异步函数,用于取消单个点赞
async function cancelLike(id, key) {
    try {
        // 发送POST请求到抖音的接口,用于取消点赞
        await fetch("https://www.douyin.com/aweme/v1/web/commit/item/digg/?aid=6383",  {
            "headers": {
                "accept": "application/json, text/plain, */*",
                "accept-language": "zh-CN,zh;q=0.9",
                "bd-ticket-guard-ree-public-key": key,
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            },
            "referrer": "https://www.douyin.com/user/self?modal_id=7308336895358930212",
            "referrerPolicy": "strict-origin-when-cross-origin",
            "body": `aweme_id=${id}&item_type=0&type=0`,
            "method": "POST",
            "mode": "cors",
            "credentials": "include"
        });
    } catch (error) {
        // 如果取消点赞失败,捕获错误(但不做处理)
    }
}

// 设置定时器,每隔4秒执行一次fetchAndCancelLikes函数
setInterval(fetchAndCancelLikes, 4000);

// 函数,用于创建和显示一个消息框
function showMessageBox(mess) {
    // 创建消息框DOM元素,并设置样式和文本内容
    var messageBox = document.createElement('div');
    messageBox.id = 'autoMessageBox';
    messageBox.style.position = 'fixed';
    messageBox.style.top = '50%';
    messageBox.style.left = '50%';
    messageBox.style.transform = 'translate(-50%, -50%)';
    messageBox.style.padding = '20px';
    messageBox.style.backgroundColor = '#3498db';
    messageBox.style.color = 'white';
    messageBox.style.borderRadius = '5px';
    messageBox.style.zIndex = '1000';
    messageBox.style.display = 'block';
    messageBox.textContent = mess;
    document.body.appendChild(messageBox);
    return messageBox;
}

新版(容易被限流,需要反复测试)


(() => {
  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();
})();

使用方法

要使用这个脚本,只需将其添加到你的浏览器控制台中即可。脚本会自动开始工作,并在页面上显示一个消息框,告诉你已经取消的点赞数量和进度。如果不再需要执行,只需关闭浏览器或移除脚本即可。

注意事项

虽然这个脚本可以自动化取消点赞的操作,但请注意,频繁的请求可能会对抖音服务器造成不必要的负担。因此,在使用时请合理安排时间间隔,避免过度请求。

此外,需要强调的是,这个脚本仅供学习和研究使用,不得用于任何商业或非法目的。在使用过程中,请遵守抖音的使用条款和相关法律法规。


免责声明: 本脚本仅供学习和研究目的,作者不承担因使用此脚本而产生的任何责任。请确保你的行为符合相关法律法规和平台政策。

如果对你有帮助,点赞👍、收藏💖、关注🔔是我更新的动力!👋🌟🚀

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐