Greasy Fork

山东省中小学教师人工智能研修助手|稳定运行|秒过|快速省心

山东省中小学教师人工智能研修助手

当前为 2025-02-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         山东省中小学教师人工智能研修助手|稳定运行|秒过|快速省心
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  山东省中小学教师人工智能研修助手
// @author       zzzyyyyyddd
// @match        https://study.seewoedu.cn/*
// @grant        GM_xmlhttpRequest
// @connect      localhost
// @connect      127.0.0.1
// @connect      study.seewoedu.cn
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 用于跟踪面板状态的变量
    let panelVisible = false;
    let currentOverlay = null;

    // 创建遮罩层和登录页面
    function createLoginPage() {
        // 创建遮罩层
        const overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.top = '0';
        overlay.style.left = '0';
        overlay.style.width = '100%';
        overlay.style.height = '100%';
        overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
        overlay.style.zIndex = '9999';
        overlay.style.display = 'flex';
        overlay.style.justifyContent = 'center';
        overlay.style.alignItems = 'center';

        // 创建登录界面容器
        const loginContainer = document.createElement('div');
        loginContainer.style.width = '90%';
        loginContainer.style.maxWidth = '500px';
        loginContainer.style.backgroundColor = 'white';
        loginContainer.style.borderRadius = '10px';
        loginContainer.style.padding = '20px';
        loginContainer.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)';
        loginContainer.style.position = 'relative';

        // 添加关闭按钮
        const closeButton = document.createElement('div');
        closeButton.innerHTML = '×';
        closeButton.style.position = 'absolute';
        closeButton.style.top = '10px';
        closeButton.style.left = '20px';
        closeButton.style.fontSize = '24px';
        closeButton.style.cursor = 'pointer';
        closeButton.onclick = function() {
            document.body.removeChild(overlay);
            panelVisible = false;
            activateButton.textContent = '显示研修助手';
        };

        // 添加标题
        const title = document.createElement('h1');
        title.textContent = '中小学(幼儿园)教师人工智能赋能教学教研线上研修助手';
        title.style.textAlign = 'center';
        title.style.fontSize = '24px';
        title.style.margin = '20px 0';
        title.style.fontWeight = 'bold';

        // 添加使用说明
        const instructions = document.createElement('div');
        instructions.innerHTML = `
            <p style="line-height: 1.6; margin: 15px 0; text-align: center; font-size: 18px;">你好,(3月1号开始)这里支持2025年中小学(幼儿园)教师人工智能赋能教学教研线上研修活动,加我q:1556818085,备注人工智能研修,发送账号密码即可</p>
            <p style="line-height: 1.6; margin: 15px 0; text-align: center; font-size: 18px;">我会手动给你学好,先学后付,只刷视频10r(需要1分钟左右即可完成),加考试一共20r</p>
        `;

        // 创建授权码输入区域
        const authCodeLabel = document.createElement('div');
        authCodeLabel.textContent = '授权码:';
        authCodeLabel.style.margin = '20px 0 10px 0';
        authCodeLabel.style.fontSize = '18px';
        authCodeLabel.style.fontWeight = 'bold';

        const authCodeInput = document.createElement('input');
        authCodeInput.type = 'text';
        authCodeInput.placeholder = '请输入授权码';
        authCodeInput.style.width = '100%';
        authCodeInput.style.padding = '12px';
        authCodeInput.style.border = '1px solid #ccc';
        authCodeInput.style.borderRadius = '5px';
        authCodeInput.style.marginBottom = '20px';
        authCodeInput.style.boxSizing = 'border-box';
        authCodeInput.style.fontSize = '16px';

        // 创建运行按钮
        const runButton = document.createElement('button');
        runButton.textContent = '开始运行';
        runButton.style.width = '100%';
        runButton.style.padding = '15px';
        runButton.style.backgroundColor = '#4CAF50';
        runButton.style.color = 'white';
        runButton.style.border = 'none';
        runButton.style.borderRadius = '5px';
        runButton.style.cursor = 'pointer';
        runButton.style.fontSize = '18px';
        runButton.style.fontWeight = 'bold';
        runButton.style.marginTop = '15px';

        // 创建状态显示区域
        const statusArea = document.createElement('div');
        statusArea.style.margin = '20px 0';
        statusArea.style.padding = '15px';
        statusArea.style.borderRadius = '5px';
        statusArea.style.backgroundColor = '#f8f8f8';
        statusArea.style.display = 'none';
        statusArea.style.fontSize = '16px';
        statusArea.style.fontWeight = 'bold';
        statusArea.style.textAlign = 'center';

        // 添加点击事件
        runButton.onclick = function() {
            // 禁用按钮
            runButton.disabled = true;
            runButton.style.backgroundColor = '#cccccc';
            runButton.textContent = '正在运行...';

            // 显示状态区域
            statusArea.style.display = 'block';
            statusArea.textContent = '正在处理,请稍候...';

            setTimeout(function() {
                const authCode = authCodeInput.value.trim();
                if (!authCode) {
                    statusArea.textContent = '请输入有效的授权码!';
                    statusArea.style.backgroundColor = '#f8d7da';
                    statusArea.style.color = '#721c24';

                    runButton.disabled = false;
                    runButton.style.backgroundColor = '#4CAF50';
                    runButton.textContent = '开始运行';
                    return;
                }

                statusArea.textContent = '正在获取授权信息...';

                // 获取当前页面的完整cookie
                getCookies(function(cookies) {
                    statusArea.textContent = '已获取Cookie,正在验证...';

                    // 使用GM_xmlhttpRequest向本地服务发送请求
                    GM_xmlhttpRequest({
                        method: 'POST',
                        url: 'http://127.0.0.1:8888/verify',
                        data: JSON.stringify({
                            authCode: authCode,
                            cookies: cookies
                        }),
                        headers: {
                            'Content-Type': 'application/json',
                            'X-Requested-With': 'XMLHttpRequest',
                            'Origin': 'https://study.seewoedu.cn'
                        },
                        onload: function(response) {
                            try {
                                const result = JSON.parse(response.responseText);

                                if (result.success) {
                                    statusArea.textContent = result.message || '验证成功!';
                                    statusArea.style.backgroundColor = '#d4edda';
                                    statusArea.style.color = '#155724';
                                } else {
                                    statusArea.textContent = result.message || '验证失败,请检查授权码是否正确。';
                                    statusArea.style.backgroundColor = '#f8d7da';
                                    statusArea.style.color = '#721c24';
                                }
                            } catch (e) {
                                statusArea.textContent = '处理响应时出错:' + e.message;
                                statusArea.style.backgroundColor = '#f8d7da';
                                statusArea.style.color = '#721c24';
                            }

                            setTimeout(function() {
                                runButton.disabled = false;
                                runButton.style.backgroundColor = '#4CAF50';
                                runButton.textContent = '开始运行';
                            }, 3000);
                        },
                        onerror: function(error) {
                            statusArea.textContent = '连接后端服务器失败,请确保服务器已启动:' + (error.error || "未知错误");
                            statusArea.style.backgroundColor = '#f8d7da';
                            statusArea.style.color = '#721c24';

                            setTimeout(function() {
                                runButton.disabled = false;
                                runButton.style.backgroundColor = '#4CAF50';
                                runButton.textContent = '开始运行';
                            }, 3000);
                        }
                    });
                });
            }, 1000);
        };

        // 将所有元素添加到容器中
        loginContainer.appendChild(closeButton);
        loginContainer.appendChild(title);
        loginContainer.appendChild(instructions);
        loginContainer.appendChild(authCodeLabel);
        loginContainer.appendChild(authCodeInput);
        loginContainer.appendChild(runButton);
        loginContainer.appendChild(statusArea);

        overlay.appendChild(loginContainer);
        document.body.appendChild(overlay);

        return overlay;
    }

    // 获取完整cookie的函数
    function getCookies(callback) {
        // 使用GM_xmlhttpRequest发送一个请求到目标网站的某个API
        // 这个请求会自动带上完整的cookie(包括HttpOnly)
        GM_xmlhttpRequest({
            method: 'GET',
            url: 'https://study.seewoedu.cn/pc/api/v1/system/menu/getUserMenu',
            headers: {
                'X-Requested-With': 'XMLHttpRequest',
            },
            onload: function(response) {
                // 从响应头中提取cookie值
                const cookies = response.responseHeaders.match(/cookie: (.*?)(?:\r|\n)/i);
                if (cookies && cookies[1]) {
                    // 如果在响应头中找到cookie
                    console.log('从响应头获取到cookie:', cookies[1]);
                    callback(cookies[1]);
                } else {
                    // 尝试获取请求头中的cookie
                    console.log('从响应头未找到cookie,使用document.cookie');
                    callback(document.cookie);
                }
            },
            onerror: function(error) {
                // 如果请求失败,使用document.cookie作为后备
                console.log('请求失败,使用document.cookie:', error);
                callback(document.cookie);
            }
        });
    }

    // 添加一个按钮到页面右上角,点击后显示/隐藏登录界面
    const activateButton = document.createElement('button');
    activateButton.textContent = '显示研修助手';
    activateButton.style.position = 'fixed';
    activateButton.style.top = '20px';
    activateButton.style.right = '20px';
    activateButton.style.zIndex = '9998';
    activateButton.style.padding = '12px 20px';
    activateButton.style.backgroundColor = '#4CAF50';
    activateButton.style.color = 'white';
    activateButton.style.border = 'none';
    activateButton.style.borderRadius = '5px';
    activateButton.style.cursor = 'pointer';
    activateButton.style.boxShadow = '0 3px 8px rgba(0,0,0,0.3)';
    activateButton.style.fontSize = '18px';
    activateButton.style.fontWeight = 'bold';
    activateButton.style.transition = 'all 0.3s ease';

    activateButton.onclick = function() {
        if (panelVisible && currentOverlay) {
            // 如果面板已显示,则隐藏
            document.body.removeChild(currentOverlay);
            panelVisible = false;
            activateButton.textContent = '显示研修助手';
            activateButton.style.backgroundColor = '#4CAF50';
        } else {
            // 如果面板未显示,则显示
            currentOverlay = createLoginPage();
            panelVisible = true;
            activateButton.textContent = '隐藏研修助手';
            activateButton.style.backgroundColor = '#e74c3c';
        }
    };

    // 添加鼠标悬停效果
    activateButton.onmouseover = function() {
        this.style.transform = 'scale(1.05)';
        if (!panelVisible) {
            this.style.backgroundColor = '#45a049';
        } else {
            this.style.backgroundColor = '#c0392b';
        }
    };

    activateButton.onmouseout = function() {
        this.style.transform = 'scale(1)';
        if (!panelVisible) {
            this.style.backgroundColor = '#4CAF50';
        } else {
            this.style.backgroundColor = '#e74c3c';
        }
    };

    document.body.appendChild(activateButton);

    // 自动显示登录界面(页面加载后1秒)
    setTimeout(function() {
        if (!panelVisible) {
            currentOverlay = createLoginPage();
            panelVisible = true;
            activateButton.textContent = '隐藏研修助手';
            activateButton.style.backgroundColor = '#e74c3c';
        }
    }, 1000);
})();