Skip to content

openLearning挂机的时候有概率出现视频播放完整停止后,检查重新进入还是停止的情况 #1

@aicaibucai

Description

@aicaibucai

现象:有一些课程肯播放完成,但是时间是不足要求,脚本检查学习未完成后重新进入相同课程,但是因为视频在上一次已经播放完成,就会出现进度直接跳转到最后1S然后播放结束。无法自动切换到下一个视频。

解决办法:在监听进度方法查找播放器,然后执行play()方法即可。

以下是修改的代码:

`function playaaa(){
const iframes = document.querySelectorAll('iframe');
if (iframes.length > 0) {
console.log('Iframes found:', iframes);

        // 递归函数,用于遍历所有 iframe 和 frame 及其内部文档
        function findElementInFramesAndIframes(framesOrIframes) {
            for (let i = 0; i < framesOrIframes.length; i++) {
                const frameOrIframe = framesOrIframes[i];
                if (frameOrIframe.contentWindow && frameOrIframe.contentWindow.document) {
                    const doc = frameOrIframe.contentWindow.document;

                    // 在当前 frame/iframe 内查找 video 元素
                    const current_video = doc.querySelector('#video');
                    if (current_video) {
                        console.log('Video element found:', current_video);
                        return current_video; // 找到后立即返回
                    }

                    // 继续递归查找嵌套的 iframe 和 frame
                    const nestedIframes = doc.querySelectorAll('iframe');
                    const nestedFrames = doc.querySelectorAll('frame');
                    if (nestedIframes.length > 0) {
                        const foundVideo = findElementInFramesAndIframes(nestedIframes);
                        if (foundVideo) {
                            return foundVideo; // 找到后立即返回
                        }
                    }
                    if (nestedFrames.length > 0) {
                        const foundVideo = findElementInFramesAndIframes(nestedFrames);
                        if (foundVideo) {
                            return foundVideo; // 找到后立即返回
                        }
                    }
                }
            }
            return null; // 没有找到
        }

        // 开始递归查找
        const videoElement = findElementInFramesAndIframes(iframes);
        if (videoElement) {
            videoElement.play();
            console.log('Video element found:', videoElement);
        } else {
            console.log('Video element not found.');
        }
    } else {
        console.log('No iframes found.');
    }

}

// 监听课程学习进度
function monitorCourseLearningProgress() {
if (window.localStorage.getItem("scanLearningProgress") === 'true') {
console.log("扫描学习情况");
playaaa();
try {
var aa = window.document.getElementsByTagName('iframe')[1].contentWindow.document.getElementsByTagName('frame')[1].contentWindow.document.getElementsByTagName('td')[1].innerText;
if (aa.indexOf("学习完毕") != -1 /|| aa.indexOf("你已累计获取10.00分")!= -1/) {
console.log("学习完毕")
window.localStorage.setItem("scanLearningProgress", "false")
autoConfirm(3000, '学习完毕,是否自动学习下一节课?(3秒后无操作,将默认学习)', function () {
window.location.reload();
});
} else {
window.errorCount = window.errorCount || 0; // 错误次数计数器
if (aa === window.txtInfo) {
layer.msg("第" + ++window.errorCount + "次检测到学习时间没发生变化
(这是学习平台自身的BUG,过一会就好了。如持续5次未检测到变化,将刷新页面重试)
" + aa, {time: 10000})
if (window.errorCount >= 5) {
window.localStorage.setItem("scanLearningProgress", "false")
window.location.reload();
}
} else {
window.errorCount = 0;
}
window.txtInfo = aa;
}
} catch (err) {
}
}
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions