Greasy Fork

Greasy Fork is available in English.

抖音清空点赞

2024/2/17 13:14:22

目前为 2024-02-17 提交的版本,查看 最新版本

// ==UserScript==
// @name        抖音清空点赞
// @namespace   Violentmonkey Scripts
// @match       https://www.douyin.com/user/self?showTab=like
// @grant       none
// @version     1.0
// @author      Kalicyh
// @license     MIT
// @description 2024/2/17 13:14:22
// ==/UserScript==

(function() {
    'use strict';

    let key = JSON.parse(localStorage.getItem('security-sdk/s_sdk_cert_key')).data.replace(/^pub\./, '');
    let max_cursorTemp = 0;
    let intervalId = null;
    let executionCount = 0;
    let notificationCounter = 0;

    function startUnlike() {
        intervalId = setInterval(() => {
            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"
            }).then((response) => {
                response.json().then(({ aweme_list, max_cursor }) => {
                    max_cursorTemp = max_cursor;
                    aweme_list.map(({ aweme_id }) => {
                        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&showTab=like",
                            "referrerPolicy": "strict-origin-when-cross-origin",
                            "body": `aweme_id=${aweme_id}&item_type=0&type=0`,
                            "method": "POST",
                            "mode": "cors",
                            "credentials": "include"
                        });
                        executionCount++;
                        notificationCounter++;
                        if (notificationCounter >= 5) {
                            showNotification(executionCount);
                            notificationCounter = 0;
                        }
                    })
                })
            })
        }, 1200);
    }

    function stopUnlike() {
        clearInterval(intervalId);
        intervalId = null;
    }

    function createSwitch() {
        const switchContainer = document.createElement('div');
        switchContainer.style.position = 'fixed';
        switchContainer.style.top = '15px';
        switchContainer.style.right = '310px';
        switchContainer.style.zIndex = '9999';

        const switchLabel = document.createElement('label');
        switchLabel.style.position = 'relative';
        switchLabel.style.display = 'inline-block';
        switchLabel.style.width = '60px';
        switchLabel.style.height = '34px';

        const switchInput = document.createElement('input');
        switchInput.type = 'checkbox';
        switchInput.style.opacity = '0';
        switchInput.style.width = '0';
        switchInput.style.height = '0';

        const slider = document.createElement('span');
        slider.style.position = 'absolute';
        slider.style.cursor = 'pointer';
        slider.style.top = '0';
        slider.style.left = '0';
        slider.style.right = '0';
        slider.style.bottom = '0';
        slider.style.backgroundColor = '#ccc';
        slider.style.borderRadius = '34px';
        slider.style.transition = '0.4s';

        const round = document.createElement('span');
        round.style.position = 'absolute';
        round.style.height = '26px';
        round.style.width = '26px';
        round.style.left = '4px';
        round.style.bottom = '4px';
        round.style.backgroundColor = 'white';
        round.style.borderRadius = '50%';
        round.style.transition = '0.4s';

        switchLabel.appendChild(switchInput);
        switchLabel.appendChild(slider);
        switchLabel.appendChild(round);
        switchContainer.appendChild(switchLabel);

        switchInput.addEventListener('change', (event) => {
            if (event.target.checked) {
                startUnlike();
                slider.style.backgroundColor = '#4CAF50'; // Green background color
                round.style.transform = 'translateX(26px)';
            } else {
                stopUnlike();
                slider.style.backgroundColor = '#ccc'; // Default background color
                round.style.transform = 'translateX(0)';
            }
        });

        document.body.appendChild(switchContainer);
    }

    function showNotification(count) {
        const notification = document.createElement('div');
        notification.textContent = `已取消点赞 ${count} 个视频`;
        notification.style.position = 'fixed';
        notification.style.bottom = '20px';
        notification.style.right = '20px';
        notification.style.backgroundColor = 'rgba(0, 128, 0, 0.7)';
        notification.style.padding = '10px';
        notification.style.borderRadius = '5px';
        notification.style.color = '#fff';
        notification.style.zIndex = '9999';

        document.body.appendChild(notification);

        setTimeout(() => {
            notification.remove();
        }, 3000);
    }

    createSwitch();
})();