Skip Elearning Auto

Auto skip Goertek E-learning courses by directly sending requests

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Skip Elearning Auto
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Auto skip Goertek E-learning courses by directly sending requests
// @author       lepecoder
// @match        https://goertek-elearning.21tb.com/els/html/courseStudyItem/courseStudyItem.learn.do?*
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    let countdown = 5;
    let countdownInterval = null;

    // 创建提示信息元素
    function createInfoPanel() {
        if (document.getElementById('skipElearningPanel')) return;

        const panel = document.createElement('div');
        panel.id = 'skipElearningPanel';
        panel.innerHTML = `跳过学习工具已就绪<br><span id="countdownText" style="font-size: 12px;">(${countdown}s 后可点击)</span>`;
        panel.style.position = 'fixed';
        panel.style.top = '10px';
        panel.style.right = '10px';
        panel.style.zIndex = '9999';
        panel.style.padding = '10px';
        panel.style.backgroundColor = '#ffffcc';
        panel.style.border = '1px solid #ffcc00';
        panel.style.borderRadius = '5px';
        panel.style.fontSize = '14px';
        panel.style.maxWidth = '300px';
        panel.style.cursor = 'not-allowed';
        panel.style.opacity = '0.7';
        panel.addEventListener('click', handleClick);
        document.body.appendChild(panel);

        // 添加提示
        const tip = document.createElement('div');
        tip.textContent = '自动跳过学习';
        tip.style.fontSize = '12px';
        tip.style.marginTop = '5px';
        tip.style.color = '#666';
        panel.appendChild(tip);

        // 开始倒计时
        startCountdown();
    }

    // 开始倒计时
    function startCountdown() {
        countdown = 5;
        updateCountdownDisplay();

        countdownInterval = setInterval(() => {
            countdown--;
            updateCountdownDisplay();

            if (countdown <= 0) {
                clearInterval(countdownInterval);
                enablePanel();
            }
        }, 1000);
    }

    // 更新倒计时显示
    function updateCountdownDisplay() {
        const countdownText = document.getElementById('countdownText');
        if (countdownText) {
            if (countdown > 0) {
                countdownText.textContent = `(${countdown}s 后可点击)`;
            } else {
                countdownText.textContent = '(点击跳过学习)';
            }
        }
    }

    // 启用面板点击功能
    function enablePanel() {
        const panel = document.getElementById('skipElearningPanel');
        if (panel) {
            panel.style.cursor = 'pointer';
            panel.style.opacity = '1.0';
        }
    }

    // 禁用面板点击功能
    function disablePanel() {
        const panel = document.getElementById('skipElearningPanel');
        if (panel) {
            panel.style.cursor = 'not-allowed';
            panel.style.opacity = '0.7';
        }
    }

    // 处理点击事件
    function handleClick() {
        if (countdown > 0) return; // 倒计时期间不允许点击
        skipElearning();
    }

    // 更新提示信息
    function updateInfoPanel(message, color = '#000000') {
        // 确保面板存在
        if (!document.getElementById('skipElearningPanel')) {
            createInfoPanel();
        }

        const panel = document.getElementById('skipElearningPanel');
        if (panel) {
            panel.firstChild.textContent = message;
            panel.style.color = color;
        }
    }

    // 提取courseId
    function getCourseId() {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get('courseId');
    }

    // 获取学习记录
    function getStudyRecord(courseId) {
        return new Promise((resolve, reject) => {
            const data = JSON.stringify({
                "courseId": courseId,
                "sourceId": courseId,
                "providerCorpCode": "goertek"
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
                if (this.readyState === 4) {
                    if (this.status === 200) {
                        try {
                            const response = JSON.parse(this.responseText);
                            if (response.bizResult && response.bizResult.length > 0) {
                                // 返回整个bizResult数组
                                resolve(response.bizResult);
                            } else {
                                reject(new Error('学习记录为空'));
                            }
                        } catch (e) {
                            reject(new Error('解析学习记录失败: ' + e.message));
                        }
                    } else {
                        reject(new Error(`获取学习记录失败: HTTP ${this.status}`));
                    }
                }
            });

            xhr.open("POST", "https://goertek-elearning.21tb.com/tbc-rms/record/getStudyRecordList");
            xhr.setRequestHeader("-local", "zh_CN");
            xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");

            // 复制当前页面的cookie
            const cookieHeader = document.cookie;
            if (cookieHeader) {
                xhr.setRequestHeader("Cookie", cookieHeader);
            }

            xhr.send(data);
        });
    }

    // 更新学习记录
    function updateStudyRecord(record) {
        return new Promise((resolve, reject) => {
            const data = JSON.stringify({
                "recordId": record.recordId,
                "courseId": record.courseId,
                "sourceId": record.courseId,
                "providerCorpCode": "goertek",
                "chapterId": record.chapterId,
                "resourceId": record.resourceId,
                "timeToFinish": record.timeToFinish,
                "currentPosition": record.timeToFinish,
                "type": "video",
                "currentStudyTime": record.timeToFinish,
                "pageIndex": 0,
                "platform": "PC"
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
                if (this.readyState === 4) {
                    if (this.status === 200) {
                        resolve(this.responseText);
                    } else {
                        reject(new Error(`跳过学习失败: HTTP ${this.status}`));
                    }
                }
            });

            xhr.open("POST", "https://goertek-elearning.21tb.com/tbc-rms/record/updateCourseRecord");
            xhr.setRequestHeader("-local", "zh_CN");
            xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");

            // 复制当前页面的cookie
            const cookieHeader = document.cookie;
            if (cookieHeader) {
                xhr.setRequestHeader("Cookie", cookieHeader);
            }

            xhr.send(data);
        });
    }

    // 主要功能函数
    async function skipElearning() {
        // 禁用面板防止重复点击
        disablePanel();
        if (countdownInterval) {
            clearInterval(countdownInterval);
        }

        updateInfoPanel('正在获取课程ID...', '#0000ff');

        try {
            const courseId = getCourseId();
            if (!courseId) {
                throw new Error('无法从URL中获取课程ID');
            }

            updateInfoPanel('正在获取学习记录...', '#0000ff');
            console.log('[SkipElearning] 获取学习记录,courseId:', courseId);
            const records = await getStudyRecord(courseId);
            console.log('[SkipElearning] 学习记录数量:', records.length);

            updateInfoPanel(`正在跳过学习 (${records.length}个视频)...`, '#0000ff');

            // 为每个记录发送更新请求
            let successCount = 0;
            for (let i = 0; i < records.length; i++) {
                try {
                    updateInfoPanel(`正在跳过学习 (${i+1}/${records.length})...`, '#0000ff');
                    const result = await updateStudyRecord(records[i]);
                    console.log(`[SkipElearning] 更新记录 ${i+1} 结果:`, result);
                    successCount++;
                } catch (error) {
                    console.error(`[SkipElearning] 更新记录 ${i+1} 失败:`, error);
                }
            }

            updateInfoPanel(`跳过完成! 成功: ${successCount}/${records.length} 页面即将刷新`, '#00aa00');
            setTimeout(() => {
                location.reload();
            }, 1000);
        } catch (error) {
            console.error('[SkipElearning] 错误:', error);
            updateInfoPanel('跳过失败: ' + error.message, '#ff0000');
            // 重新开始倒计时
            startCountdown();
        }
    }

    // 页面加载完成后初始化
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', createInfoPanel);
    } else {
        createInfoPanel();
    }
})();