From a86b8112a5de0d5d12653567124fc4a0f0e15730 Mon Sep 17 00:00:00 2001 From: fluent <51286304+Lceoliu@users.noreply.github.com> Date: Tue, 19 Sep 2023 22:56:14 +0800 Subject: [PATCH 1/5] Update xuexitong.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适应新版学习通 --- xuexitong.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/xuexitong.js b/xuexitong.js index 26ea1b4..6f94045 100644 --- a/xuexitong.js +++ b/xuexitong.js @@ -3,9 +3,88 @@ */ // 当前小节 -window.unitCount = $(".ncells h4").index($(".currents")) + 1; +window.unitCount = $(".posCatalog_active").index(".posCatalog_select"); // 获取小节数量 -window.unit = $(".ncells h4").length; +window.unit = $(".posCatalog_level span em").length; + + + +function main(){ + const frameObj = $("iframe").eq(0).contents().find("iframe.ans-insertvideo-online"); + const videoNum = frameObj.length; + if(videoNum > 0){ + console.log("%c当前小节中包含 " + videoNum + " 个视频","color:#FF7A38;font-size:18px"); + var v_done = 0; + // 添加事件处理程序 + addEventListener("playdone" ,()=>{ + v_done++; + if(v_done > videoNum){ + // 下一节 + } else if(v_done < videoNum){ + watchVideo(frameObj, v_done) + } else { + console.log("%c本小节视频播放完毕,等待跳转至下一小节...","font-size:18px");nextUnit(); + } + }); + // 播放 + watchVideo(frameObj, v_done); + } else { + if(window.unitCount < window.unit){ + console.log("%c当前小节中无视频,6秒后将跳转至下一节","font-size:18px"); + nextUnit(); + } else { + console.log("%c好了好了,毕业了","color:red;font-size:18px"); + } + } +} +function watchVideo(frameObj, v_done){ + // 添加播放事件 + var playDoneEvent = new Event("playdone"); + // 获取播放对象 + var v = undefined; + v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); + window.a = v; + // 设置倍速 + try{ v.playbackRate = 2;} + catch(e){console.error("倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:"+e); nextUnit(); return;} + // 播放 + v.play(); + console.log("%c正在 " + v.playbackRate + " 倍速播放第 " + (v_done + 1) + " 个视频","font-size:18px"); + // 循环获取播放进度 + window.inter = setInterval(()=>{ + v = window.a; + if(v.currentTime >= v.duration){ + dispatchEvent(playDoneEvent); + clearInterval(window.inter); + } + if(v.paused){ + v.play(); + } + },1000); +} +function nextUnit(){ + console.log("%c即将进入下一节...","color:red;font-size:18px"); + setTimeout(() => { + $(document).scrollTop($(document).height()-$(window).height()); + $("#prevNextFocusNext").click() + $(".nextChapter").eq(0).click() + $("#prevNextFocusNext").click() + $(".nextChapter").eq(0).click() + console.log("%c行了别看了,我知道你学会了,下一节","color:red;font-size:18px");// (已经跳转" +(++window.unitCount)+"次)"); + if(window.unitCount++ < window.unit){ setTimeout(() => main(), 10000) } + }, 6000); +} +console.log("%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", "color:#6dbcff", "color:red", window.unit, "color:#6dbcff", "color:red", window.unitCount, "font-size:8px"); +main();/** + * 学习通 + */ + +// 当前小节 +window.unitCount = $(".posCatalog_active").index(".posCatalog_select"); +// 获取小节数量 +window.unit = $(".posCatalog_level span em").length; + + function main(){ const frameObj = $("iframe").eq(0).contents().find("iframe.ans-insertvideo-online"); @@ -40,9 +119,10 @@ function watchVideo(frameObj, v_done){ var playDoneEvent = new Event("playdone"); // 获取播放对象 var v = undefined; - v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0);window.a = v; + v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); + window.a = v; // 设置倍速 - try{ v.playbackRate = 8;} + try{ v.playbackRate = 2;} catch(e){console.error("倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:"+e); nextUnit(); return;} // 播放 v.play(); @@ -63,10 +143,13 @@ function nextUnit(){ console.log("%c即将进入下一节...","color:red;font-size:18px"); setTimeout(() => { $(document).scrollTop($(document).height()-$(window).height()); - $(".orientationright").click(); + $("#prevNextFocusNext").click() + $(".nextChapter").eq(0).click() + $("#prevNextFocusNext").click() + $(".nextChapter").eq(0).click() console.log("%c行了别看了,我知道你学会了,下一节","color:red;font-size:18px");// (已经跳转" +(++window.unitCount)+"次)"); if(window.unitCount++ < window.unit){ setTimeout(() => main(), 10000) } }, 6000); } console.log("%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", "color:#6dbcff", "color:red", window.unit, "color:#6dbcff", "color:red", window.unitCount, "font-size:8px"); -main(); \ No newline at end of file +main(); From 05c41f109a9b4bd958fa6118f9e3f144938de208 Mon Sep 17 00:00:00 2001 From: fluent <51286304+Lceoliu@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:01:01 +0800 Subject: [PATCH 2/5] Update new xuexitong.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适应新版学习通系统 --- xuexitong.js | 327 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 196 insertions(+), 131 deletions(-) diff --git a/xuexitong.js b/xuexitong.js index 6f94045..8243ecb 100644 --- a/xuexitong.js +++ b/xuexitong.js @@ -7,75 +7,108 @@ window.unitCount = $(".posCatalog_active").index(".posCatalog_select"); // 获取小节数量 window.unit = $(".posCatalog_level span em").length; - - -function main(){ - const frameObj = $("iframe").eq(0).contents().find("iframe.ans-insertvideo-online"); - const videoNum = frameObj.length; - if(videoNum > 0){ - console.log("%c当前小节中包含 " + videoNum + " 个视频","color:#FF7A38;font-size:18px"); - var v_done = 0; - // 添加事件处理程序 - addEventListener("playdone" ,()=>{ - v_done++; - if(v_done > videoNum){ - // 下一节 - } else if(v_done < videoNum){ - watchVideo(frameObj, v_done) - } else { - console.log("%c本小节视频播放完毕,等待跳转至下一小节...","font-size:18px");nextUnit(); - } - }); - // 播放 - watchVideo(frameObj, v_done); - } else { - if(window.unitCount < window.unit){ - console.log("%c当前小节中无视频,6秒后将跳转至下一节","font-size:18px"); - nextUnit(); - } else { - console.log("%c好了好了,毕业了","color:red;font-size:18px"); - } - } +function main() { + const frameObj = $("iframe") + .eq(0) + .contents() + .find("iframe.ans-insertvideo-online"); + const videoNum = frameObj.length; + if (videoNum > 0) { + console.log( + "%c当前小节中包含 " + videoNum + " 个视频", + "color:#FF7A38;font-size:18px" + ); + var v_done = 0; + // 添加事件处理程序 + addEventListener("playdone", () => { + v_done++; + if (v_done > videoNum) { + // 下一节 + } else if (v_done < videoNum) { + watchVideo(frameObj, v_done); + } else { + console.log( + "%c本小节视频播放完毕,等待跳转至下一小节...", + "font-size:18px" + ); + nextUnit(); + } + }); + // 播放 + watchVideo(frameObj, v_done); + } else { + if (window.unitCount < window.unit) { + console.log("%c当前小节中无视频,6秒后将跳转至下一节", "font-size:18px"); + nextUnit(); + } else { + console.log("%c好了好了,毕业了", "color:red;font-size:18px"); + } + } } -function watchVideo(frameObj, v_done){ - // 添加播放事件 - var playDoneEvent = new Event("playdone"); - // 获取播放对象 - var v = undefined; - v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); - window.a = v; - // 设置倍速 - try{ v.playbackRate = 2;} - catch(e){console.error("倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:"+e); nextUnit(); return;} - // 播放 - v.play(); - console.log("%c正在 " + v.playbackRate + " 倍速播放第 " + (v_done + 1) + " 个视频","font-size:18px"); - // 循环获取播放进度 - window.inter = setInterval(()=>{ - v = window.a; - if(v.currentTime >= v.duration){ - dispatchEvent(playDoneEvent); - clearInterval(window.inter); - } - if(v.paused){ - v.play(); - } - },1000); +function watchVideo(frameObj, v_done) { + // 添加播放事件 + var playDoneEvent = new Event("playdone"); + // 获取播放对象 + var v = undefined; + v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); + window.a = v; + // 设置倍速 + try { + v.playbackRate = 2; + } catch (e) { + console.error( + "倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:" + e + ); + nextUnit(); + return; + } + // 播放 + v.play(); + console.log( + "%c正在 " + v.playbackRate + " 倍速播放第 " + (v_done + 1) + " 个视频", + "font-size:18px" + ); + // 循环获取播放进度 + window.inter = setInterval(() => { + v = window.a; + if (v.currentTime >= v.duration) { + dispatchEvent(playDoneEvent); + clearInterval(window.inter); + } + if (v.paused) { + v.play(); + } + }, 1000); } -function nextUnit(){ - console.log("%c即将进入下一节...","color:red;font-size:18px"); - setTimeout(() => { - $(document).scrollTop($(document).height()-$(window).height()); - $("#prevNextFocusNext").click() - $(".nextChapter").eq(0).click() - $("#prevNextFocusNext").click() - $(".nextChapter").eq(0).click() - console.log("%c行了别看了,我知道你学会了,下一节","color:red;font-size:18px");// (已经跳转" +(++window.unitCount)+"次)"); - if(window.unitCount++ < window.unit){ setTimeout(() => main(), 10000) } - }, 6000); +function nextUnit() { + console.log("%c即将进入下一节...", "color:red;font-size:18px"); + setTimeout(() => { + $(document).scrollTop($(document).height() - $(window).height()); + $("#prevNextFocusNext").click(); + $(".nextChapter").eq(0).click(); + $("#prevNextFocusNext").click(); + $(".nextChapter").eq(0).click(); + console.log( + "%c行了别看了,我知道你学会了,下一节", + "color:red;font-size:18px" + ); // (已经跳转" +(++window.unitCount)+"次)"); + if (window.unitCount++ < window.unit) { + setTimeout(() => main(), 10000); + } + }, 6000); } -console.log("%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", "color:#6dbcff", "color:red", window.unit, "color:#6dbcff", "color:red", window.unitCount, "font-size:8px"); -main();/** +console.log( + "%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", + "color:#6dbcff", + "color:red", + window.unit, + "color:#6dbcff", + "color:red", + window.unitCount, + "font-size:8px" +); +main(); +/** * 学习通 */ @@ -84,72 +117,104 @@ window.unitCount = $(".posCatalog_active").index(".posCatalog_select"); // 获取小节数量 window.unit = $(".posCatalog_level span em").length; - - -function main(){ - const frameObj = $("iframe").eq(0).contents().find("iframe.ans-insertvideo-online"); - const videoNum = frameObj.length; - if(videoNum > 0){ - console.log("%c当前小节中包含 " + videoNum + " 个视频","color:#FF7A38;font-size:18px"); - var v_done = 0; - // 添加事件处理程序 - addEventListener("playdone" ,()=>{ - v_done++; - if(v_done > videoNum){ - // 下一节 - } else if(v_done < videoNum){ - watchVideo(frameObj, v_done) - } else { - console.log("%c本小节视频播放完毕,等待跳转至下一小节...","font-size:18px");nextUnit(); - } - }); - // 播放 - watchVideo(frameObj, v_done); - } else { - if(window.unitCount < window.unit){ - console.log("%c当前小节中无视频,6秒后将跳转至下一节","font-size:18px"); - nextUnit(); - } else { - console.log("%c好了好了,毕业了","color:red;font-size:18px"); - } - } +function main() { + const frameObj = $("iframe") + .eq(0) + .contents() + .find("iframe.ans-insertvideo-online"); + const videoNum = frameObj.length; + if (videoNum > 0) { + console.log( + "%c当前小节中包含 " + videoNum + " 个视频", + "color:#FF7A38;font-size:18px" + ); + var v_done = 0; + // 添加事件处理程序 + addEventListener("playdone", () => { + v_done++; + if (v_done > videoNum) { + // 下一节 + } else if (v_done < videoNum) { + watchVideo(frameObj, v_done); + } else { + console.log( + "%c本小节视频播放完毕,等待跳转至下一小节...", + "font-size:18px" + ); + nextUnit(); + } + }); + // 播放 + watchVideo(frameObj, v_done); + } else { + if (window.unitCount < window.unit) { + console.log("%c当前小节中无视频,6秒后将跳转至下一节", "font-size:18px"); + nextUnit(); + } else { + console.log("%c好了好了,毕业了", "color:red;font-size:18px"); + } + } } -function watchVideo(frameObj, v_done){ - // 添加播放事件 - var playDoneEvent = new Event("playdone"); - // 获取播放对象 - var v = undefined; - v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); - window.a = v; - // 设置倍速 - try{ v.playbackRate = 2;} - catch(e){console.error("倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:"+e); nextUnit(); return;} - // 播放 - v.play(); - console.log("%c正在 " + v.playbackRate + " 倍速播放第 " + (v_done + 1) + " 个视频","font-size:18px"); - // 循环获取播放进度 - window.inter = setInterval(()=>{ - v = window.a; - if(v.currentTime >= v.duration){ - dispatchEvent(playDoneEvent); - clearInterval(window.inter); - } - if(v.paused){ - v.play(); - } - },1000); +function watchVideo(frameObj, v_done) { + // 添加播放事件 + var playDoneEvent = new Event("playdone"); + // 获取播放对象 + var v = undefined; + v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); + window.a = v; + // 设置倍速 + try { + v.playbackRate = 2; + } catch (e) { + console.error( + "倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:" + e + ); + nextUnit(); + return; + } + // 播放 + v.play(); + console.log( + "%c正在 " + v.playbackRate + " 倍速播放第 " + (v_done + 1) + " 个视频", + "font-size:18px" + ); + // 循环获取播放进度 + window.inter = setInterval(() => { + v = window.a; + if (v.currentTime >= v.duration) { + dispatchEvent(playDoneEvent); + clearInterval(window.inter); + } + if (v.paused) { + v.play(); + } + }, 1000); } -function nextUnit(){ - console.log("%c即将进入下一节...","color:red;font-size:18px"); - setTimeout(() => { - $(document).scrollTop($(document).height()-$(window).height()); - $("#prevNextFocusNext").click() - $(".nextChapter").eq(0).click() - $("#prevNextFocusNext").click() - $(".nextChapter").eq(0).click() - console.log("%c行了别看了,我知道你学会了,下一节","color:red;font-size:18px");// (已经跳转" +(++window.unitCount)+"次)"); - if(window.unitCount++ < window.unit){ setTimeout(() => main(), 10000) } - }, 6000); +function nextUnit() { + console.log("%c即将进入下一节...", "color:red;font-size:18px"); + setTimeout(() => { + $(document).scrollTop($(document).height() - $(window).height()); + $("#prevNextFocusNext").click(); + $(".nextChapter").eq(0).click(); + $("#prevNextFocusNext").click(); + $(".nextChapter").eq(0).click(); + console.log( + "%c行了别看了,我知道你学会了,下一节", + "color:red;font-size:18px" + ); // (已经跳转" +(++window.unitCount)+"次)"); + if (window.unitCount++ < window.unit) { + setTimeout(() => main(), 10000); + } + }, 6000); } -console.log("%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", "color:#6dbcff", "color:red", window.unit, "color:#6dbcff", "color:red", window.unitCount, "font-size:8px"); +console.log( + "%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", + "color:#6dbcff", + "color:red", + window.unit, + "color:#6dbcff", + "color:red", + window.unitCount, + "font-size:8px" +); main(); From 63d04377c897e7cf2493044a87deb47df127fd34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=98=E6=A2=93=E9=98=B3?= <3552971348@qq.com> Date: Fri, 8 Mar 2024 19:37:54 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=EF=BC=881=EF=BC=89=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E5=B0=8F=E8=8A=82=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E5=B0=8F=E8=8A=82=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E5=B0=86=E7=AB=A0=E8=8A=82=E6=A0=87=E9=A2=98=E4=B9=9F?= =?UTF-8?q?=E7=AE=97=E5=85=A5=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=AF=8F=E8=BF=87?= =?UTF-8?q?=E4=B8=80=E7=AB=A0=E7=B4=A2=E5=BC=95=E5=B0=B1=E4=BC=9A=E5=A4=9A?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E3=80=82=20=EF=BC=882=EF=BC=89=20=E5=9C=A8?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=B0=8F=E8=8A=82=E5=90=8E=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E5=BD=93=E5=89=8D=E4=B8=8D=E5=9C=A8=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=88=99=E5=85=88=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E8=A7=86=E9=A2=91=E8=BF=9B=E5=85=A5=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=8E=9F=E5=85=88=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=9A=E5=AF=BC=E8=87=B4=E9=94=99=E8=BF=87=E8=A7=86?= =?UTF-8?q?=E9=A2=91=20=EF=BC=883=EF=BC=89=E5=80=8D=E9=80=9F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=A4=B1=E6=95=88=EF=BC=8C=E5=BB=BA=E8=AE=AE=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E6=8E=89=E6=88=96=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=88=96?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=85=B6=E4=BB=96=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xuexitong.js | 200 ++++++++++++++++----------------------------------- 1 file changed, 62 insertions(+), 138 deletions(-) diff --git a/xuexitong.js b/xuexitong.js index 8243ecb..e091a6f 100644 --- a/xuexitong.js +++ b/xuexitong.js @@ -3,157 +3,81 @@ */ // 当前小节 -window.unitCount = $(".posCatalog_active").index(".posCatalog_select"); -// 获取小节数量 -window.unit = $(".posCatalog_level span em").length; +// 确保页面中存在至少一个激活的小节元素 +const activeElement = $(".posCatalog_select.posCatalog_active"); -function main() { - const frameObj = $("iframe") - .eq(0) - .contents() - .find("iframe.ans-insertvideo-online"); - const videoNum = frameObj.length; - if (videoNum > 0) { - console.log( - "%c当前小节中包含 " + videoNum + " 个视频", - "color:#FF7A38;font-size:18px" - ); - var v_done = 0; - // 添加事件处理程序 - addEventListener("playdone", () => { - v_done++; - if (v_done > videoNum) { - // 下一节 - } else if (v_done < videoNum) { - watchVideo(frameObj, v_done); - } else { - console.log( - "%c本小节视频播放完毕,等待跳转至下一小节...", - "font-size:18px" - ); - nextUnit(); - } - }); - // 播放 - watchVideo(frameObj, v_done); - } else { - if (window.unitCount < window.unit) { - console.log("%c当前小节中无视频,6秒后将跳转至下一节", "font-size:18px"); - nextUnit(); - } else { - console.log("%c好了好了,毕业了", "color:red;font-size:18px"); - } - } -} -function watchVideo(frameObj, v_done) { - // 添加播放事件 - var playDoneEvent = new Event("playdone"); - // 获取播放对象 - var v = undefined; - v = frameObj.contents().eq(v_done).find("video#video_html5_api").get(0); - window.a = v; - // 设置倍速 - try { - v.playbackRate = 2; - } catch (e) { - console.error( - "倍速设置失败!此节可能有需要回复内容,不影响,跳至下一节。错误信息:" + e - ); - nextUnit(); - return; +if (activeElement.length) { + // 先获取所有章节标题元素的父级(假设章节标题和小节同级) + const chapterTitles = $(".posCatalog_select:has(.posCatalog_title)"); + + // 获取章节标题之外的所有小节元素 + const substantiveSiblings = $(".posCatalog_select").not(chapterTitles); + + // 在实质性小节中找到当前活跃小节的索引 + let unitCount = substantiveSiblings.index(activeElement); + + // jQuery 的 .index() 方法返回值是从0开始的,如果需要从1开始计数,可以加1 + unitCount += 1; + + // 若找不到有效的小节同级元素,则设定默认值 + if (!substantiveSiblings.length || unitCount === -1) { + console.warn("未找到有效的.posCatalog_select同级元素!"); + unitCount = -1; } - // 播放 - v.play(); - console.log( - "%c正在 " + v.playbackRate + " 倍速播放第 " + (v_done + 1) + " 个视频", - "font-size:18px" - ); - // 循环获取播放进度 - window.inter = setInterval(() => { - v = window.a; - if (v.currentTime >= v.duration) { - dispatchEvent(playDoneEvent); - clearInterval(window.inter); - } - if (v.paused) { - v.play(); - } - }, 1000); -} -function nextUnit() { - console.log("%c即将进入下一节...", "color:red;font-size:18px"); - setTimeout(() => { - $(document).scrollTop($(document).height() - $(window).height()); - $("#prevNextFocusNext").click(); - $(".nextChapter").eq(0).click(); - $("#prevNextFocusNext").click(); - $(".nextChapter").eq(0).click(); - console.log( - "%c行了别看了,我知道你学会了,下一节", - "color:red;font-size:18px" - ); // (已经跳转" +(++window.unitCount)+"次)"); - if (window.unitCount++ < window.unit) { - setTimeout(() => main(), 10000); - } - }, 6000); -} -console.log( - "%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", - "color:#6dbcff", - "color:red", - window.unit, - "color:#6dbcff", - "color:red", - window.unitCount, - "font-size:8px" -); -main(); -/** - * 学习通 - */ -// 当前小节 -window.unitCount = $(".posCatalog_active").index(".posCatalog_select"); + // 将结果赋值到全局作用域 + window.unitCount = unitCount; +} else { + console.error("未找到激活的小节元素!"); +} // 获取小节数量 window.unit = $(".posCatalog_level span em").length; function main() { - const frameObj = $("iframe") - .eq(0) - .contents() - .find("iframe.ans-insertvideo-online"); - const videoNum = frameObj.length; - if (videoNum > 0) { - console.log( - "%c当前小节中包含 " + videoNum + " 个视频", - "color:#FF7A38;font-size:18px" - ); - var v_done = 0; - // 添加事件处理程序 - addEventListener("playdone", () => { - v_done++; - if (v_done > videoNum) { - // 下一节 - } else if (v_done < videoNum) { - watchVideo(frameObj, v_done); - } else { + // 尝试点击视频按钮 + document.querySelector('li[title="视频"]').click(); + // 等待几秒后执行视频存在性检查和其他操作 + setTimeout(() => { + const frameObj = $("iframe") + .eq(0) + .contents() + .find("iframe.ans-insertvideo-online"); + const videoNum = frameObj.length; + if (videoNum > 0) { + console.log( + "%c当前小节中包含 " + videoNum + " 个视频", + "color:#FF7A38;font-size:18px" + ); + var v_done = 0; + // 添加事件处理程序 + addEventListener("playdone", () => { + v_done++; + if (v_done > videoNum) { + // 下一节 + } else if (v_done < videoNum) { + watchVideo(frameObj, v_done); + } else { + console.log( + "%c本小节视频播放完毕,等待跳转至下一小节...", + "font-size:18px" + ); + nextUnit(); + } + }); + // 播放 + watchVideo(frameObj, v_done); + } else { + if (window.unitCount < window.unit) { console.log( - "%c本小节视频播放完毕,等待跳转至下一小节...", + "%c当前小节中无视频,6秒后将跳转至下一节", "font-size:18px" ); nextUnit(); + } else { + console.log("%c好了好了,毕业了", "color:red;font-size:18px"); } - }); - // 播放 - watchVideo(frameObj, v_done); - } else { - if (window.unitCount < window.unit) { - console.log("%c当前小节中无视频,6秒后将跳转至下一节", "font-size:18px"); - nextUnit(); - } else { - console.log("%c好了好了,毕业了", "color:red;font-size:18px"); } - } + }, 3000); // 3000毫秒(即3秒)后执行 } function watchVideo(frameObj, v_done) { // 添加播放事件 From 9f26b4654fc167afe9d6b7c637c2252c3862191b Mon Sep 17 00:00:00 2001 From: Lceoliu <2994536684@qq.com> Date: Sun, 20 Oct 2024 05:40:16 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Fix=E6=97=A0=E6=B3=95=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xuexitong.js | 94 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/xuexitong.js b/xuexitong.js index e091a6f..96f3dfa 100644 --- a/xuexitong.js +++ b/xuexitong.js @@ -1,34 +1,85 @@ /** * 学习通 */ +/** + * 仍然存在问题: + * 1. 学习通可能要求必须完成每一节的答题才能进入下一节,这种情况下脚本会卡住,需要手动完成答题 + * 2. 视频播放完毕后可能会出现悬浮答题界面,但可以通过等待或点击下一节按钮跳过 + */ -// 当前小节 -// 确保页面中存在至少一个激活的小节元素 -const activeElement = $(".posCatalog_select.posCatalog_active"); +// 新版学习通元素Selectors,便于后续修改 +const videoButtonSelector = "#video button"; +const courseTreeNodeSelector = "#coursetree"; +const courseLayerSelector = ".posCatalog_select"; +const courseTitleSelector = ".posCatalog_name"; +const courseSectionSelector = ".posCatalog_sbar"; +const courseCompletedSelector = "span.icon_Completed.prevTips"; +/** + * + * @returns {Array<{section: string, course: string, element: HTMLElement}>} + * @description 获取所有课程数据 + */ +function GetAllCourses() { + let courseData = []; -if (activeElement.length) { - // 先获取所有章节标题元素的父级(假设章节标题和小节同级) - const chapterTitles = $(".posCatalog_select:has(.posCatalog_title)"); + const courseTree = document.querySelector(courseTreeNodeSelector); - // 获取章节标题之外的所有小节元素 - const substantiveSiblings = $(".posCatalog_select").not(chapterTitles); + // 所有层级课程元素都含有 .posCatalog_select 类名 + // 但是章节名称元素还有一个额外的 .firstLayer 类名 + const courses = courseTree.querySelectorAll( + courseLayerSelector + ":not(.firstLayer)" + ); - // 在实质性小节中找到当前活跃小节的索引 - let unitCount = substantiveSiblings.index(activeElement); + courses.forEach((course) => { + const courseName = course + .querySelector(courseTitleSelector) + ?.getAttribute("title"); + const sectionName = course.querySelector( + courseSectionSelector + )?.textContent; - // jQuery 的 .index() 方法返回值是从0开始的,如果需要从1开始计数,可以加1 - unitCount += 1; + if (courseName && sectionName) { + courseData.push({ + section: sectionName.trim(), + course: courseName.trim(), + element: course, + }); + } else { + console.warn("未找到课程名称或章节名称!这可能会是一个错误!", course); + } + }); - // 若找不到有效的小节同级元素,则设定默认值 - if (!substantiveSiblings.length || unitCount === -1) { - console.warn("未找到有效的.posCatalog_select同级元素!"); - unitCount = -1; - } + return courseData; +} - // 将结果赋值到全局作用域 - window.unitCount = unitCount; -} else { - console.error("未找到激活的小节元素!"); +const courseDatas = GetAllCourses(); +const courseCount = courseDatas.length; +console.log("课程数量:", courseCount); +let unitCount = 0; +try { + // section是章节,例如"1.1.2",取小数点前的数字即为章节数 + unitCount = courseDatas[courseCount - 1].section?.split(".")[0]; + console.log("章节数量:", unitCount); +} catch (error) { + console.error("获取章节数量失败!(并不影响程序运作)", error); +} +// 当前小节 +// 页面中激活的小节元素 +const completedCourses = document.querySelectorAll(courseCompletedSelector); +if (completedCourses.length > 0) { + // 选取当前小节 + const currentCourseData = courseDatas[completedCourses.length]; + //console.log("当前小节:", currentCourseData); + let currentCourse = currentCourseData?.element; + if (currentCourse) { + // 跳转到当前小节 + Array.from(currentCourse.querySelectorAll("*")).forEach( + (e) => e.hasAttribute("onclick") && e.click() + ) + ? [0].click() + : null; + } + window.currentCourseCount = courseDatas.indexOf(currentCourseData); } // 获取小节数量 window.unit = $(".posCatalog_level span em").length; @@ -131,6 +182,7 @@ function nextUnit() { } }, 6000); } + console.log( "%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", "color:#6dbcff", From e332aa2012ebc53012061d5b975816a350d2c6d0 Mon Sep 17 00:00:00 2001 From: Lceoliu <2994536684@qq.com> Date: Sun, 20 Oct 2024 05:48:20 +0800 Subject: [PATCH 5/5] =?UTF-8?q?Fix=E8=A7=86=E9=A2=91=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xuexitong.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/xuexitong.js b/xuexitong.js index 96f3dfa..79f8359 100644 --- a/xuexitong.js +++ b/xuexitong.js @@ -81,12 +81,17 @@ if (completedCourses.length > 0) { } window.currentCourseCount = courseDatas.indexOf(currentCourseData); } -// 获取小节数量 -window.unit = $(".posCatalog_level span em").length; + +// 存取小节数量 +window.unit = unitCount; function main() { // 尝试点击视频按钮 - document.querySelector('li[title="视频"]').click(); + // try { + // document.querySelector(videoButtonSelector).click(); + // } catch (error) { + // console.error("点击视频按钮失败!", error); + // } // 等待几秒后执行视频存在性检查和其他操作 setTimeout(() => { const frameObj = $("iframe") @@ -130,6 +135,7 @@ function main() { } }, 3000); // 3000毫秒(即3秒)后执行 } + function watchVideo(frameObj, v_done) { // 添加播放事件 var playDoneEvent = new Event("playdone"); @@ -165,6 +171,7 @@ function watchVideo(frameObj, v_done) { } }, 1000); } + function nextUnit() { console.log("%c即将进入下一节...", "color:red;font-size:18px"); setTimeout(() => { @@ -184,13 +191,17 @@ function nextUnit() { } console.log( - "%c 欢迎使用本脚本,此科目有%c %d %c个小节,当前为 %c第%d小节 %c-chao", + "%c 欢迎使用本脚本,此科目共有%c %d %c个章节%c %d %c节课,当前为 %c第%d节课:%s %c-chao", "color:#6dbcff", "color:red", window.unit, "color:#6dbcff", "color:red", - window.unitCount, + courseCount, + "color:#6dbcff", + "color:red", + window.currentCourseCount + 1, + courseDatas[window.currentCourseCount]?.course, "font-size:8px" ); main();