赞
踩
学习通刷课太痛苦?试试这个Js脚本
- /**
- * 本脚本用于学习通自动刷课,仅做学习用途
- * 转发请注明作者以及来源
- */
- /**定义全局变量 */
- var array_echelon;//顺序执行梯队
- /**定义事件 */
- let dealEvent = new Event("redeal", { bubbles: false, cancelable: false });
- /**监听事件 */
- document.addEventListener("redeal", function () {
- dealAnsEchelon(array_echelon);
- });
- /**初始化 */
- function initAll() {
- console.log("获取当前页面任务中···");
- var ansiframe = window.frames["iframe"].contentWindow.document;//获取任务iframe
- var array_ans = ansiframe.querySelectorAll(".ans-attach-ct");//获取任务数组
- var array_type = getiframesType(array_ans);//获取任务属性
- var array_document = getAlliframesdocument(array_ans);//获取任务数组的document
- array_echelon = distributeAns(array_type, array_document);//获取顺序执行的任务的梯队
- console.log("当前页面任务数量为:" + array_echelon.length);
- /**释放内存 */
- ansiframe = null;
- array_ans = null;
- array_type = null;
- array_document = null;
- }
- /**工具函数 */
- //获取任务属性
- function getiframesType(array_ans) {
- var array_iframe_type = new Array();
- for (let ans of array_ans) {
- var jsonstr = ans.querySelector("iframe").getAttribute("data");
- var json = JSON.parse(jsonstr);
- array_iframe_type.push(json.type);
- }
- return array_iframe_type;
- }
- //获取任务document
- function getAlliframesdocument(array_ans) {
- var array_ans_iframe_document = new Array();
- for (let ans of array_ans) {
- array_ans_iframe_document.push(ans.querySelector("iframe").contentWindow.document);
- }
- return array_ans_iframe_document;
- }
- //搭配document以及相应的执行函数
- function joinAns(idocument, handler) {
- var array_temp = new Array();
- array_temp.push(idocument, handler);
- return array_temp;
- }
- //按任务属性分配执行函数
- function distributeAns(array_type, array_document) {
- var array_iframe_echelon = new Array();
- array_type.forEach((type, index) => {
- switch (type) {
- case ".mp4": { array_iframe_echelon.push(joinAns(array_document[index], videoHandler)); break; }
- case ".wmv": { array_iframe_echelon.push(joinAns(array_document[index], videoHandler)); break; }
- case ".avi": { array_iframe_echelon.push(joinAns(array_document[index], videoHandler)); break; }
- case ".mkv": { array_iframe_echelon.push(joinAns(array_document[index], videoHandler)); break; }
- case ".pptx": { array_iframe_echelon.push(joinAns(array_document[index], pptxHandler)); break; }
- case ".pdf": { array_iframe_echelon.push(joinAns(array_document[index], pptxHandler)); break; }
- case ".ppt": { array_iframe_echelon.push(joinAns(array_document[index], pptxHandler)); break; }
- case ".mp3": { array_iframe_echelon.push(joinAns(array_document[index], audioHandler)); break; }
- case ".wav": { array_iframe_echelon.push(joinAns(array_document[index], audioHandler)); break; }
- default: { array_iframe_echelon.push(joinAns(array_document[index], ignoreAns)); break; }
- }
- });
- return array_iframe_echelon;
- }
- //处理单个任务
- function dealSingleAns(singleans) {
- singleans[1](singleans[0]);
- }
- /**执行函数 */
- //直接跳过
- function skipChapter() {
- console.log("跳过章节");
- var chapter_next = document.querySelector("#prevNextFocusNext");
- chapter_next.click();
- setTimeout(function () {
- var tip = document.querySelector(".maskDiv.jobFinishTip.maskFadeOut");
- if (tip != null) {
- var tip_nextChapter = document.querySelector(".jb_btn.jb_btn_92.fr.fs14.nextChapter");
- tip_nextChapter.click();
- }
- setTimeout(() => {
- initAll();
- dealAnsEchelon(array_echelon);
- }, 5000);
- }, 2000);
- }
- //忽略任务
- function ignoreAns() {
- console.log("无法处理,忽略任务");
- setTimeout(() => {
- document.dispatchEvent(dealEvent);
- }, 1500);
- }
- //处理视频
- function videoHandler(idocument) {
- console.log("处理视频任务中···");
- var video = idocument.querySelector("video");
- var video_play = idocument.querySelector(".vjs-big-play-button");
- var video_doublespeed = idocument.querySelector(".vjs-menu-item");
- video_play.click();
- video_doublespeed.click();
- video.addEventListener("ended", function () {
- document.dispatchEvent(dealEvent);
- }, { once: true });
- }
- //处理ppt&pdf
- function pptxHandler(idocument) {
- console.log("处理PPT任务中···");
- var sdocument = idocument.querySelector("iframe").contentWindow.document;
- var currentHeight = 0;
- var finalHeight = sdocument.documentElement.scrollHeight;
- var timer = setInterval(function () {
- if (currentHeight >= finalHeight) {
- clearInterval(timer);
- document.dispatchEvent(dealEvent);
- return;
- }
- currentHeight += 400;
- sdocument.defaultView.scrollTo(0, currentHeight);
- }, 1000);
- }
- //处理音频
- function audioHandler(idocument) {
- console.log("处理音频任务中···");
- var audio = idocument.querySelector("audio");
- var audio_play = idocument.querySelector(".vjs-play-control.vjs-control.vjs-button");
- audio_play.click();
- audio.addEventListener("ended", function () {
- document.dispatchEvent(dealEvent);
- }, { once: true });
- }
- /**任务梯队顺序处理 */
- function dealAnsEchelon(array_echelon) {
- console.log("待处理任务数量为:" + array_echelon.length);
- if (array_echelon.length != 0) {
- dealSingleAns(array_echelon[0]);
- array_echelon.shift();
- return;
- }
- skipChapter();
- }
- /**执行代码 */
- initAll();
- dealAnsEchelon(array_echelon);
代码基本都给了注释,目前没发现Bug
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。