lc自用-步数助手

lc自用-为步数网站添加预设按钮

目前為 2025-05-10 提交的版本,檢視 最新版本

// ==UserScript==
// @name         lc自用-步数助手
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  lc自用-为步数网站添加预设按钮
// @author       Your name
// @match        http://8.140.250.130/bushu/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 生成随机数的函数
    function getRandomNumber(base, range) {
        const min = base - range;
        const max = base + range;
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    // 检查是否为移动设备
    function isMobile() {
        return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
    }

    // 等待页面加载完成
    window.addEventListener('load', function() {
        // 修改"账号"文字
        const labels = document.querySelectorAll('.layui-form-label');
        labels.forEach(label => {
            if (label.textContent === '账号') {
                label.textContent = '账aaa号';
            }
        });

        // 创建按钮容器
        const buttonContainer = document.createElement('div');
        buttonContainer.style.marginTop = '10px';
        buttonContainer.style.textAlign = 'center';
        buttonContainer.style.display = 'flex';
        buttonContainer.style.justifyContent = 'center';
        buttonContainer.style.gap = isMobile() ? '5px' : '10px';
        buttonContainer.style.flexWrap = 'wrap';
        buttonContainer.style.width = '100%';

        // 预设值数组
        const presetValues = [
            { name: '八千', value: 8000 },
            { name: '一万三', value: 13000 },
            { name: '一万八', value: 18000 },
            { name: '两万一', value: 21000 }
        ];

        // 创建按钮
        presetValues.forEach(preset => {
            const button = document.createElement('button');
            button.textContent = preset.name;
            
            // 根据设备类型设置不同的样式
            if (isMobile()) {
                button.style.padding = '6px 10px';
                button.style.fontSize = '12px';
                button.style.minWidth = '60px';
                button.style.margin = '2px';
            } else {
                button.style.padding = '8px 15px';
                button.style.fontSize = '14px';
                button.style.minWidth = '80px';
            }
            
            button.style.backgroundColor = '#0094D9';
            button.style.color = 'white';
            button.style.border = 'none';
            button.style.borderRadius = '8px';
            button.style.cursor = 'pointer';
            button.style.flex = '1';
            button.style.maxWidth = isMobile() ? '45%' : '120px';

            // 添加点击事件
            button.addEventListener('click', function() {
                const input = document.querySelector('#steps');
                if (input) {
                    const randomValue = getRandomNumber(preset.value, 500);
                    input.value = randomValue;
                    
                    // 延迟500毫秒后自动点击提交按钮
                    setTimeout(() => {
                        const submitButton = document.querySelector('.subButton');
                        if (submitButton) {
                            submitButton.click();
                        }
                    }, 500);
                }
            });

            buttonContainer.appendChild(button);
        });

        // 找到提交按钮并插入按钮容器
        const submitButton = document.querySelector('.subButton');
        if (submitButton) {
            submitButton.parentNode.insertBefore(buttonContainer, submitButton.nextSibling);
        }
    });
})();