陕西省专业技术人员继续教育公需课专业课自动播放

陕西专技公需课专业课职称继续教育自动播放

// ==UserScript==
// @name         陕西省专业技术人员继续教育公需课专业课自动播放
// @namespace    https://github.com/hat12/
// @version      1.8
// @description  陕西专技公需课专业课职称继续教育自动播放
// @author       hat12
// @license      MIT
// @match        http://jxjy01.xidian.edu.cn/learnspace/learn/learn/templatethree/courseware_index.action*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var current = -1

    var playVideo = function(){
        const iframe = document.querySelector('#mainFrame').contentWindow.document
        const classes = document.getElementsByClassName('s_point')
        current = current === -1 ? Array.from(document.getElementsByClassName('s_point')).findIndex(x => x.classList.contains('s_pointerct')) : current + 1
        const next = current < classes.length - 1 && classes[current + 1]
        const video = iframe.querySelector('video')
        const track = iframe.querySelector('.trace_btn')

        if(!video){
            setTimeout(playVideo, 2000)
            return
        }

        var trackId = setInterval(() => {
            track.click()
        }, 2000)

        var timeId = setInterval(() => {
            if (video.ended && timeId) {
                clearInterval(timeId)
                timeId = null

                video.playbackRate = 1

                setTimeout(() => {
                    clearInterval(trackId)
                    next && next.click()
                    setTimeout(playVideo, 2000); // Adjusted delay for starting the next video
                }, 10 * 2000)
            }
        }, 2000);
    }

    var confirmation = document.createElement('div');
    confirmation.innerHTML = `
        <div style="position: fixed; top: 50%; left: 43%; transform: translate(-50%, -50%) scale(1); padding: 10px; background: rgba(255, 255, 255, 0.9); border: none; border-radius: 10px; z-index: 9999; text-align: center; font-family: 'Arial', sans-serif; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);">
            <img src="https://img.picgo.net/2024/05/29/1716973684846ff265a96759568cb.png " style="width: 50%; max-width: 300px; height: auto; margin-bottom: 10px;">
            <h2 style="margin-bottom: 10px; font-size: 14px; color: #333;">点击开始学习,===代购课程加 qgjxjy3===  </h2>
            <button id='startLearning' style="padding: 5px 10px; font-size: 12px; background: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer;">开始学习</button>
        </div>
    `;

    document.body.appendChild(confirmation);

    document.getElementById('startLearning').addEventListener('click', function() {
        confirmation.style.display = "none";
        setTimeout(playVideo, 5000);
    });

})();