注:只是用来学习,能力有限写的不好,不一定都有用,仅供思路参考。
function auto() {
console.log('脚本开始执行。。。。');
// 获取所有的章节
let arr = document.querySelectorAll('.posCatalog_level .posCatalog_select .posCatalog_name');
let currentIndex = 0;//当前章节
window.isTick = false;// 判断任务点是否标记完成,默认为未完成
window.video = undefined;//视频
let first = true;//控制每一章节video播放只执行一次
window.setInterval(() => {
console.log('每10s,监测一次视频状态');
// 最顶部的iframe
let topIframe = document.querySelector('#iframe');
// 判断是否是暂停或首次播放
if (window.video&&window.video.paused || first) {
if (currentIndex === 0) {
player();
} else {
// 如果是暂停后的,不需要等加载完
if(topIframe.onload){
player()
}else{
topIframe.onload = () => {
player()
};
}
}
}
// 判断视频是否播放完,和任务点是否完成-满足一个就行
if (window.isTick || video && video.ended) {
currentIndex++;
console.log(`第${currentIndex + 1}章节播放。。。。`);
// 只需要点击第一章节,其他的自动点击
arr[currentIndex].click();
// 重置状态
window.isTick = false;
first = true;
}
}, 10000)
}
// 获取任务点,和video,并播放视频
function player() {
// 任务点
let tick = document.querySelector('#iframe').contentWindow.document.querySelector('.ans-job-icon ');
//满足该条件则表示该任务点已完成
window.isTick = window.getComputedStyle(tick)['backgroundPosition'] === '0px -24px';
if (!window.video) {
// 不存在则获取
window.video = document.querySelector('#iframe').contentWindow.document.querySelector('iframe').contentWindow.document.getElementById('video_html5_api');
} else {
// 存在则判断是否是最新的
if (window.video.play()) {
// 上面是最新的话会直接执行。
first = false;
} else {
// 获取最新的
window.video = document.querySelector('#iframe').contentWindow.document.querySelector('iframe').contentWindow.document.getElementById('video_html5_api');
}
}
}
// 执行
auto();
用法:打开学习通第一节,打开浏览器控制台,把代码粘贴上去,回车执行即可。