Greasy Fork

Greasy Fork is available in English.

斗鱼鱼塘商城兑换工具

A script to perform the Douyu prize conversion function.

当前为 2024-12-31 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        斗鱼鱼塘商城兑换工具
// @namespace   YourNamespaceHere
// @version     1.0
// @description  A script to perform the Douyu prize conversion function.
// @match       https://www.douyu.com/pages/fish-act/mine*
// @grant       GM_addStyle
// @grant       GM_xmlhttpRequest
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    const ctnid = `72e357ae075816fbdebd0950930`; ///用户ID
    const roomid = `12345`; //房间ID
    // 用于判断页面是否加载完成的标志变量
    let pageLoaded = false;

    // 监听页面加载状态改变事件
    window.addEventListener('load', function () {
        pageLoaded = true;
        initScript();
    });

    // 初始化脚本的函数,在页面加载完成后执行具体操作
    function initScript() {
        // 添加悬浮窗样式
        GM_addStyle(`
            #overlay {
                position: fixed;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                background-color: rgba(255, 255, 255, 0.9);
                padding: 20px;
                border-radius: 10px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
                display: none;
                z-index: 9999;
            }

            button {
                margin: 5px;
                padding: 10px 20px;
                font-size: 16px;
                cursor: pointer;
                border: none;
                border-radius: 5px;
            }

            button.start {
                background-color: green;
                color: white;
            }

            button.stop {
                background-color: red;
                color: white;
            }

            select {
                margin: 5px;
                padding: 10px;
                font-size: 16px;
                border: 1px solid #ccc;
                border-radius: 5px;
            }
        `);

        // 创建悬浮窗元素及按钮
        const overlay = document.createElement('div');
        overlay.id = 'overlay';
        const startButton = document.createElement('button');
        startButton.textContent = '启动';
        startButton.className = 'start';
        const stopButton = document.createElement('button');
        stopButton.textContent = '停止';
        stopButton.className = 'stop';

        // 创建下拉菜单元素
        const selectMenu = document.createElement('select');

        // 从图片中提取的名字及对应的值
        const items = [
            { value: 'PROP_1', text: '3级粉丝牌 初级水手' },
            { value: 'PROP_2', text: '3级粉丝牌 精英士官' },
            { value: 'PROP_3', text: '6级粉丝牌 心动卡' },
            { value: 'FREE_PROP_1', text: '10 陪伴印章' },
            { value: 'FREE_PROP_2', text: '30 陪伴印章' },
            { value: 'FREE_PROP_3', text: '50 陪伴印章' },
            { value: 'YC_TY_1', text: '0.1 鱼翅' },
            { value: 'YC_TY_2', text: '0.5 鱼翅' },
            { value: 'YC_TY_3', text: '1 鱼翅' },
            { value: 'YW_1', text: '100 鱼丸' },
            { value: 'YW_2', text: '200 鱼丸' },
            { value: 'YW_3', text: '500 鱼丸' },
            { value: 'YC_CHIP_1', text: '2 鱼翅碎片' },
            { value: 'YC_CHIP_2', text: '5 鱼翅碎片' }
        ];

        // 循环创建下拉菜单选项
        items.forEach(item => {
            const option = document.createElement('option');
            option.value = item.value;
            option.textContent = item.text;
            selectMenu.appendChild(option);
        });

        overlay.appendChild(selectMenu);
        overlay.appendChild(startButton);
        overlay.appendChild(stopButton);
        document.body.appendChild(overlay);

        // 用于存储当前选择的index值的变量
        let selectedIndexValue = 'PROP_1';

        // 监听下拉菜单选项改变事件,更新选中的index值
        selectMenu.addEventListener('change', function () {
            selectedIndexValue = this.value;
        });

        // 用于控制兑换代码是否执行的标志变量
        let isRunning = false;


        // 显示悬浮窗
        function showOverlay() {
            overlay.style.display = 'block';
        }

        // 隐藏悬浮窗
        function hideOverlay() {
            overlay.style.display = 'none';
        }

        // 点击启动按钮的处理函数
        startButton.addEventListener('click', function () {
            isRunning = true;
            runExchangeLoop();
        });

        // 点击停止按钮的处理函数
        stopButton.addEventListener('click', function () {
            isRunning = false;
        });

        // 模拟兑换代码执行的函数(这里简化了之前的fetch请求,实际要替换成完整准确的)
        async function exchange() {
            try {
                await GM_xmlhttpRequest({
                    method: 'POST',
                    url: "https://www.douyu.com/japi/revenuenc/web/actfans/convert/convertOpt",
                    headers: {
                        "accept": "application/json, text/plain, */*",
                        "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
                        "content-type": "application/x-www-form-urlencoded",
                        "priority": "u=1, i",
                        "sec-ch-ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
                        "sec-ch-ua-mobile": "?0",
                        "sec-ch-ua-platform": "\"Windows\"",
                        "sec-fetch-dest": "empty",
                        "sec-fetch-mode": "cors",
                        "sec-fetch-site": "same-origin"
                    },
                    referrer: "https://www.douyu.com/pages/fish-act/shop",
                    referrerPolicy: "strict-origin-when-cross-origin",
                    data: `ctn=${ctnid}&rid=${roomid}&index=${selectedIndexValue}`,
                    onload: function (response) {
                        console.log('兑换请求响应:', response);
                    },
                    onerror: function (error) {
                        console.error('兑换出现错误:', error);
                    }
                });
            } catch (error) {
                console.error('兑换出现错误:', error);
            }
        }

        // 循环执行兑换代码的函数(根据标志变量控制)
        async function runExchangeLoop() {
            let count = 0;
            while (isRunning && count < 200) {
                await exchange();
                count++;
            }
            if (count >= 200) {
                isRunning = false;
            }
        }

        // 页面加载完成后显示悬浮窗
        showOverlay();
    }
})();