Greasy Fork

智慧中小学学习助手

智慧中小学自动学习工具

目前为 2025-01-26 提交的版本。查看 最新版本

// ==UserScript==
// @name         智慧中小学学习助手
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  智慧中小学自动学习工具
// @author       Your name
// @match        https://auth.smartedu.cn/*
// @match        https://www.smartedu.cn/*
// @grant        GM_xmlhttpRequest
// @copyright
// @license CUSTOM
// @connect      zhihuizhongxiaoxue.a1.luyouxia.net
// ==/UserScript==

(function() {
    'use strict';

    // 创建样式
    const style = document.createElement('style');
    style.textContent = `
        .study-helper {
            position: fixed;
            top: 20px;
            right: 20px;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 300px;
            z-index: 10000;
        }
        .study-helper h2 {
            margin: 0 0 15px 0;
            color: #333;
            font-size: 18px;
        }
        .study-helper .notice {
            font-size: 14px;
            color: #666;
            margin-bottom: 15px;
            line-height: 1.4;
        }
        .study-helper .input-group {
            margin-bottom: 10px;
        }
        .study-helper label {
            display: block;
            margin-bottom: 5px;
            color: #333;
            font-size: 14px;
        }
        .study-helper input {
            width: 100%;
            padding: 8px;
            margin-bottom: 0;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .study-helper button {
            width: 100%;
            padding: 10px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        .study-helper button:hover:not(:disabled) {
            background: #45a049;
        }
        .study-helper button:disabled {
            background: #cccccc;
            cursor: not-allowed;
        }
        .study-helper .result {
            margin-top: 10px;
            padding: 10px;
            border-radius: 4px;
            font-size: 14px;
        }
        .study-helper .success {
            background: #e8f5e9;
            color: #2e7d32;
        }
        .study-helper .error {
            background: #ffebee;
            color: #c62828;
        }
        .study-helper .loading {
            background: #fff3e0;
            color: #ef6c00;
        }
        @keyframes spin {
            0% { content: "⋮"; }
            33% { content: "⋰"; }
            66% { content: "⋯"; }
            100% { content: "⋱"; }
        }
        .study-helper .loading::after {
            content: "⋮";
            display: inline-block;
            margin-left: 5px;
            animation: spin 1s infinite steps(4);
        }
    `;
    document.head.appendChild(style);

    // 创建HTML结构
    const div = document.createElement('div');
    div.className = 'study-helper';
    div.innerHTML = `
        <h2>智慧中小学学习助手</h2>
        <div class="notice">
            尊敬的用户你好,需要你输入username,password,和授权码,
            授权码在<a href="https://www.qianxun1688.com/links/E46F5C6A" target="_blank">这里获取</a>,
            注意,授权码有使用次数,请确认您的账号密码正确。
        </div>
        <div class="input-group">
            <label for="helper-username">用户名:</label>
            <input type="text" id="helper-username" class="helper-input" placeholder="请输入用户名" />
        </div>
        <div class="input-group">
            <label for="helper-password">密码:</label>
            <input type="password" id="helper-password" class="helper-input" placeholder="请输入密码" />
        </div>
        <div class="input-group">
            <label for="helper-authcode">授权码:</label>
            <input type="text" id="helper-authcode" class="helper-input" placeholder="请输入授权码" />
        </div>
        <button id="helper-submit">开始学习</button>
        <div id="helper-result" class="result"></div>
    `;
    document.body.appendChild(div);

    // 添加提交事件处理
    document.getElementById('helper-submit').addEventListener('click', function() {
        const submitBtn = this;
        const username = document.getElementById('helper-username').value.trim();
        const password = document.getElementById('helper-password').value.trim();
        const authcode = document.getElementById('helper-authcode').value.trim();
        const resultDiv = document.getElementById('helper-result');

        // 添加调试日志
        console.log('发送的数据:', {
            username: username,
            password: password,
            auth_code: authcode
        });

        if (!username || !password || !authcode) {
            resultDiv.className = 'result error';
            resultDiv.textContent = '请填写所有必要信息!';
            return;
        }

        // 禁用按钮并显示加载状态
        submitBtn.disabled = true;
        submitBtn.textContent = '学习中';
        resultDiv.className = 'result loading';
        resultDiv.textContent = '正在执行学习任务,请耐心等待';

        // 发送API请求
        GM_xmlhttpRequest({
            method: 'POST',
            url: 'http://zhihuizhongxiaoxue.a1.luyouxia.net:23757/api/study',
            headers: {
                'Content-Type': 'application/json'
            },
            data: JSON.stringify({
                username: username,
                password: password,
                auth_code: authcode
            }),
            onload: function(response) {
                console.log('服务器响应:', response.responseText);

                try {
                    const result = JSON.parse(response.responseText);
                    if (response.status === 200) {
                        resultDiv.className = 'result success';
                        resultDiv.textContent = `${result.message},剩余使用次数:${result.remaining_uses}`;
                        submitBtn.textContent = '学习完成';
                    } else {
                        resultDiv.className = 'result error';
                        resultDiv.textContent = result.error || '请求失败,请稍后重试';
                        submitBtn.disabled = false;
                        submitBtn.textContent = '重试';
                    }
                } catch (e) {
                    resultDiv.className = 'result error';
                    resultDiv.textContent = '解析响应失败,请稍后重试';
                    submitBtn.disabled = false;
                    submitBtn.textContent = '重试';
                }
            },
            onerror: function(error) {
                console.log('请求错误:', error);
                resultDiv.className = 'result error';
                resultDiv.textContent = '网络请求失败,请检查网络连接';
                submitBtn.disabled = false;
                submitBtn.textContent = '重试';
            }
        });
    });
})();