Greasy Fork

憨憨大转盘

点击开始按钮后每10秒访问网址以进行抽奖,并在控制台输出抽奖结果

// ==UserScript==
// @name         憨憨大转盘
// @version      1.0
// @author       PoppyGuy
// @icon         https://hhanclub.top/favicon.ico
// @description  点击开始按钮后每10秒访问网址以进行抽奖,并在控制台输出抽奖结果
// @match        https://hhanclub.top/lucky.php
// @license      MIT
// @grant        GM_xmlhttpRequest
// @namespace https://greasyfork.org/users/1304869
// ==/UserScript==

(function() {
    'use strict';

    let intervalId;

    function startLuckyDraw() {
        console.log('开始抽奖...');
        intervalId = setInterval(() => {
            GM_xmlhttpRequest({
                method: "POST",
                url: "https://hhanclub.top/plugin/lucky-draw",
                onload: function(response) {
                    let data = JSON.parse(response.responseText);
                    let prizeText = data.data.prize_text; // 提取 prize_text 值
                    console.log(prizeText);
                }
            });
        }, 10000); // 每10秒执行一次
    }

    function stopLuckyDraw() {
        console.log('停止抽奖...');
        clearInterval(intervalId);
    }

    let buttonContainer = document.createElement('div');
    buttonContainer.style.position = 'fixed';
    buttonContainer.style.top = '20px';
    buttonContainer.style.left = '20px';
    buttonContainer.style.zIndex = '9999';
    buttonContainer.style.padding = '15px';
    buttonContainer.style.backgroundColor = '#b3ffb3'; // 淡绿色背景
    buttonContainer.style.border = '1px solid #ccc';
    buttonContainer.style.borderRadius = '5px'; // 圆角

    let startButton = document.createElement('button');
    startButton.textContent = '开始';
    startButton.style.margin = '10px';
    startButton.style.padding = '10px';
    startButton.style.backgroundColor = '#f0f0f0'; // 淡灰色按钮
    startButton.style.border = '1px solid #ccc';
    startButton.style.fontSize = '16px'; // 字体大小
    startButton.addEventListener('click', startLuckyDraw);

    let stopButton = document.createElement('button');
    stopButton.textContent = '停止';
    stopButton.style.margin = '10px';
    stopButton.style.padding = '10px';
    stopButton.style.backgroundColor = '#f0f0f0'; // 淡灰色按钮
    stopButton.style.border = '1px solid #ccc';
    stopButton.style.fontSize = '16px'; // 字体大小
    stopButton.addEventListener('click', stopLuckyDraw);

    buttonContainer.appendChild(startButton);
    buttonContainer.appendChild(stopButton);

    document.body.appendChild(buttonContainer);
})();