// ==UserScript== // @name 电子科技大学挂机宝 // @namespace www.qqkzw.com // @version 1.1.2 // @description 电子科技大学(网络教育)自动在线学习&自动考试 // @author Horjer // @require https://cdn.bootcss.com/jquery/1.8.3/jquery.min.js // @require https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js // @resource layer http://cdn.bootcdn.net/ajax/libs/layer/3.1.1/theme/default/layer.css // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @grant GM_getResourceText // @match https://student.uestcedu.com/console/main.html* // @match https://student.uestcedu.com/console/apply/student/student_learn.jsp* // @match http://learning.uestcedu.com/learning3/* // @match http://ispace.uestcedu.com/ispace2_sync/scormplayer/index_sco.jsp* // @match http://ispace.uestcedu.com/ispace2_upload/scormplayer/index_sco.jsp* // @match http://ispace.uestcedu.com/ispace2_upload/*/ch_index.html* // ***********************************特此声明*********************************************** // 该脚本完全免费,仅供学习使用,严谨倒卖!!! 如果您是通过购买所得,请找卖家退款!!! // 尊重作者权益,请勿在未经允许的情况下擅自修改代码和发布到其他平台! // 作者: Horjer // 更新时间: 2020年12月08日 // 版本: v1.1.2 // **************************************************************************************** // @downloadURL none // ==/UserScript== GM_addStyle(GM_getResourceText('layer')); GM_addStyle(".site-dir{display:none;}.site-dir li{line-height:26px;overflow:visible;list-style-type:disc;}.site-dir li a{display:block;text-decoration:none}.site-dir li a:active{color:#01AAED;}.site-dir li a.layui-this{color:#01AAED;}body .layui-layer-dir{box-shadow:none;border:1px solid #d2d2d2;}body .layui-layer-dir .layui-layer-content{padding:10px;}.site-dir a em{padding-left:5px;font-size:12px;color:#c2c2c2;font-style:normal;}"); GM_addStyle(".layui-layer-ico16,.layui-layer-loading.layui-layer-loading2{width:32px;height:32px;background:url(https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/theme/default/loading-2.gif)no-repeat;}.layui-layer-ico{background: url(https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/theme/default/icon.png) no-repeat;}"); //初始化调用 (function() { console.log("===================" + GetUrlRelativePath()) if(GetUrlRelativePath() === "/learning3/course/course_learning.jsp"){ openCoursesDir(getUrlParam("course_id")); window.top.localStorage.setItem("scanLearningProgress", "false"); autoConfirm(3000, '是否开始学习本课程?(3秒后无操作,将默认学习)', function(){ layer.msg('执行自动学习'); window.top.localStorage.setItem("scanLearningProgress", "true"); startLookCurriculum(); }); } if(GetUrlRelativePath() === '/learning3/console/'){ console.log("===========执行自动学习监听================="); monitorLogin(); setInterval(monitorCourseLearningProgress, 1000*10); //扫描 } if(GetUrlRelativePath() === "/ispace2_sync/scormplayer/index_sco.jsp"){ updateLoadInterval(); } if(GetUrlRelativePath().indexOf("/ch_index.html") != -1){ videoPage() } if(GetUrlRelativePath() === "/learning3/scorm/scoplayer/load_sco.jsp"){ videoProgress(); } if(GetUrlRelativePath() === "/learning3/scorm/scoplayer/code.htm"){ window.top.localStorage.setItem("scanLearningProgress", "true"); // 进入到该页面,就可以开始监控 } if(GetUrlRelativePath() === "/learning3/exam/portal/exam_info.jsp"){ layer.msg('请稍等,正在检查考试状况'); setTimeout(function() { examInfo(); }, 1000); } if(GetUrlRelativePath() === "/learning3/exam/portal/exam.jsp"){ layer.msg('进入考试页面'); setTimeout(function() { exam(); }, 1000); } if(GetUrlRelativePath() === "/learning3/exam/portal/view_answer.jsp"){ layer.msg('进入查看试卷页面'); setTimeout(function() { viewAnswer(); }, 1000); } if(GetUrlRelativePath() === "/console/apply/student/student_learn.jsp"){ studentLearn(); } if(GetUrlRelativePath() === "/console/main.html"){ studentLogin() } })(); // 学生管理平台登录 function studentLogin(){ $.ajax({ url:"https://student.uestcedu.com/console/user_info.jsp?" + Math.random(), dataType: "json", success:function (data){ if(!data.user_name){ if(window.invalidLayer){ layer.close(window.invalidLayer) } window.invalidLayer = layer.confirm('检测到登录已失效,是否去登录?', {icon: 3, title:'提示'}, function(index){ window.location.href = "https://student.uestcedu.com/console/"; }); } } }); setTimeout(studentLogin, 1000 * 60); } // 学生管理平台在线学习 function studentLearn(){ layer.open({ type: 1, skin: 'layui-layer-rim', //加上边框 area: ['420px', '360px'], //宽高 offset: 'rb', shade :0, content: '
该插件仅供学习使用,严谨倒卖
如插件失效,可加微信联系作者进行适配
' }); var loginName = $("input[name='txtLoginName']").val(); var password = $("input[name='txtPassword']").val(); var txtSiteId = $("input[name='txtSiteId']").val(); var coursesElement = $("#tblDataList").find("a:contains('开始学习')"); var userData = {'account':loginName, 'password' : password}; var courses = []; for (let i = 0; i < coursesElement.length; i++) { var courseElement = $(coursesElement[i]); var trElement = courseElement.parent().parent(); var courseId = courseElement.attr("onclick").split('\'')[1]; var courseName = trElement.children("td:eq(1)").text(); courses[i] = {'courseName' : courseName, 'courseId' : courseId, 'state' : '等待学习'}; } layer.confirm('一切已准备就绪,开始自动学习全部课程?(您也可以手动点击某个课程进行学习)', {icon: 3, title:'提示'}, function(index){ layer.close(index); GM_setValue("userData",userData); GM_setValue("courses",courses); GM_setValue("txtSiteId",txtSiteId); window.open(getCoursePage(courses[0].courseId)); }); } // 获取课程页面 function getCoursePage(courseId){ return "http://learning.uestcedu.com/learning3/console/?urlto=http://learning.uestcedu.com/learning3/course/course_learning.jsp?course_id=" + courseId + "&course_name=" + Math.random() } // 打开考试确认页面 function examInfo(){ var win = window.parent.parent.document.getElementById("w_lms_content").contentWindow.document.getElementById("w_sco").contentWindow; var contentId = getUrlParam("content_id"); var datas = window.localStorage.getItem(contentId); // 试题和答案 var btnExam = win.document.getElementById("btnExam"); var lookButton = btnExam.nextSibling.nextSibling; var succeedColor = win.document.getElementsByTagName("font")[1].color; // 考试是否通过,绿色就通过 if(succeedColor == 'green'){ autoConfirm(3000, '该作业已完成,是否退出?(3秒后无操作,将默认退出)', function(){ top.window.location.reload(); }); return; } if(lookButton == undefined || datas){ // win.frames["w_exam"].location.href = win.$api.fn.getActionURL("com.lemon.learning.exam.StudentExamAction?op=before_exam&exam_id=3163&reexam=" + (win.sExamStatus=="reexamine"?"1":"0")+"&script=parent.afterCheckExam()"); win.sExamStatus = ''; // 不是重考 btnExam.click(); }else{ lookButton.click(); } } // 考试答题页面 function exam(){ layer.msg('开始自动做题'); var contentId = getUrlParam("content_id"); var datas = window.localStorage.getItem(contentId); // 试题和答案 if(datas){ datas = JSON.parse(datas); } var dataTr = $("#tblDataList tr"); for (let i = 0; i < dataTr.length; i++) { const dataTrElement = $(dataTr[i]); var item = dataTrElement.find("table[isitem='1']"); // 题目table var timu = $(item.find("tr td")[0]).html(); // 题目内容 console.log(timu); var temoption = item.find("table[isitemoption='1']"); // 答案table var optiontype = temoption.attr("optiontype"); // 答案类型,单选:radio, 多选: var tds = temoption.find("tr td"); var input = $(tds[0]); // 答题input if(!datas){ // 目前还没有答案 $(tds.find("input")[0]).attr("checked", "checked"); // 全部选择A选项 }else{ // 有答案了 for (const data of datas) { if(data.timu === timu){ var temoption = item.find("table[isitemoption='1']"); // 答案选项 var answersElement = temoption.find("label"); // 可选择的答案 for (let j = 0; j < answersElement.length; j++) { const $answer = $(answersElement[j]); for (const answer of data.answer) { if(answer == $answer.html()){ var $input = $answer.parent().prev().prev().find("input") $input.attr("checked", "checked") } } } } } } } layer.msg('正在等待提交试卷中(需要15秒时间等待,否则提交试卷成绩不作数)', { icon: 16, shade: 0.3, time: -1 }); // 交卷 setTimeout(function() { parent.frames["w_right"].doSubmit(true,"console.log('您已经选择交卷,请点击确定退出考试!');"); // setTimeout(function() { // $("#cboxClose")[0].click() // }, 3000); }, 15000); } // 查看试卷 function viewAnswer(){ var trs = $("form[name='form1']").find("table tr"); var testQuestions = []; // 所有题目和答案 for (let i = 0; i < trs.length; i++) { const dataTrElement = $(trs[i]); var item = dataTrElement.find("table[isitem='1']"); // 题目table var timu = $(item.find("tr td")[0]).html(); // 题目内容 if(!timu){ continue; } var data = {"timu": timu} var temoption = item.find("table[isitemoption='1']"); // 答案选项 var answer = item.find("tr td div:last").text().replace("[参考答案:", "").split("]")[0]; // 正确答案选项 data.answer = []; for (var j=0; j本课程最少需学习:" + secondsFormat(s) +"") } // 格式化时间 function secondsFormat( s ) { var day = Math.floor( s/ (24*3600) ); // Math.floor()向下取整 var hour = Math.floor( (s - day*24*3600) / 3600); var minute = Math.floor( (s - day*24*3600 - hour*3600) /60 ); var second = s - day*24*3600 - hour*3600 - minute*60; return day + "天" + hour + "时" + minute + "分" + second + "秒"; } // 查找未学习的课程 function startLookCurriculum(){ setTimeout(function(){ console.log("查找还未读完的课程") layer.msg('查找还未读完的课程'); if($("#frame_user_score").length == 0){ // 课程没有被确认过 autoConfirm(10000, '加载课程可能发生失败,是否尝试重新加载?(10秒后无操作,将默认重新加载,如一直无法加载成功,请检查网站本身是否正常,也可联系作者查看)', function(){ enterCourse(getUrlParam("course_id")); }); return; } var success = false; var divs = $(".scorm.incomplete,.notattempt"); for(var i = 0; i < divs.length; i++) { var a = $(divs[i]).parent().parent().find("a"); var href = a.attr("href"); //if(href && href.indexOf("scorm_content") != -1){ if(href){ success = true; window.top.localStorage.setItem("scanLearningProgress", "true"); // 开始监控 a[0].click(); break; } } if(!success){ var courses = GM_getValue("courses") || []; var course; for(var j = 0; j < courses.length; j++) { if(courses[j].state === '等待学习'){ course = courses[j]; break; } } if(course != undefined){ course.state = '学习完毕'; // 修改学习状态 GM_setValue("courses", courses); autoConfirm(3000, '本课程已学完,是否自动学习下个课程?(3秒后无操作,将默认学习)', function(){ window.top.location.href = getCoursePage(course.courseId); }); }else{ var retry = setTimeout(function(){ startLookCurriculum(); }, 3000); layer.alert('课程已全部学习完毕', {icon: 3, title:'提示'}, function(index){ window.clearInterval(retry); layer.close(index); }); } } }, 5000); } // 显示课程目录 function openCoursesDir(currentCourseId){ var courses = GM_getValue("courses") || []; if(courses.length <= 0){ return; } var siteDir = ''; layer.open({ type: 1 ,content: siteDir ,skin: 'layui-layer-dir' ,area: 'auto' ,maxHeight: $(window).height() - 300 ,title: '课程目录' //,closeBtn: false ,offset: 'r' ,shade: false ,success: function(layero, index){ layer.style(index, { marginLeft: -15 }); } }); } // 查看视频的页面处理方法 function videoPage(){ console.log("进入课程页面"); $(".chapter span:last").click(); // 先点击一下最后一个PPT } // 监听课程学习进度 function monitorCourseLearningProgress(){ if(window.localStorage.getItem("scanLearningProgress") === 'true'){ console.log("扫描学习情况"); layer.msg('扫描学习情况'); 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){ console.log("第" + ++window.errorCount + "次检测到学习时间没发生变化:" + aa) if(window.errorCount > 10){ window.localStorage.setItem("scanLearningProgress", "false") window.location.reload(); } }else{ window.errorCount = 0; } window.txtInfo = aa; } }catch(err){} } } // 自动确认 function autoConfirm(time, content, fun, fun2){ var timeoutIndex = setTimeout(function(){ window.clearInterval(timeoutIndex); fun(); }, time); layer.confirm(content, {icon: 3, title:'提示'}, function(index){ window.clearInterval(timeoutIndex); fun(); }, function(index){ window.clearInterval(timeoutIndex); if(fun2 != undefined){ fun2(); } }); } // 监听登录状态 function monitorLogin(){ console.log("监听登录状态"); layer.msg('监听登录状态'); if(!validLogin()){ var userData = GM_getValue("userData"); if(!userData){ layer.confirm('无效登录状态。本地没有您的账号信息,无法完成自动登录,需要进行手动登录?', {icon: 3, title:'提示'}, function(index){ window.location.href = "https://student.uestcedu.com/console/"; }); }else{ layer.msg('无效登录状态,正在尝试自动登录'); login(userData); window.location.reload(); } } setTimeout(monitorLogin, 1000 * 60); // 1分监听一次登录状态 } // 校验网络学习平台登录状态 function validLogin(){ var login = true; $.ajax({ url: "http://learning.uestcedu.com/learning3/json/login_info.jsp", async: false, dataType:"json", success:function(data){ if(data.username === ''){ console.log("无效登录状态"); login = false; }else{ layer.msg('当前登录状态有效'); } } }) return login; } // 登录网络学习平台 function login(userData){ $.ajax({ url: "http://learning.uestcedu.com/learning3/servlet/com.lemon.web.ActionServlet?handler=com%2euestc%2euser%2eUserLoginAction&op=login&type=to_learning&op=execscript&urlto=&script=parent.afterAction()&_no_html=1&" + Math.random(), headers : { 'Referer': 'http://learning.uestcedu.com/learning3/' }, type: "POST", data: { "txtLoginName": userData.account, "txtPassword": userData.password, "txtCourseId": "2894", "ran": "0.3607649358110765" }, success:function(data){ console.log(data); var body = document.getElementsByTagName("body"); var div = document.createElement("div"); div.innerHTML = ''; document.body.appendChild(div) } }) } // 获取当前窗口相对路径 function GetUrlRelativePath(){ var url = document.location.toString(); var arrUrl = url.split("//"); var start = arrUrl[1].indexOf("/"); var relUrl = arrUrl[1].substring(start);//stop省略,截取从start开始到结尾的所有字符 if(relUrl.indexOf("?") != -1){ relUrl = relUrl.split("?")[0]; } return relUrl; } //获取url中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } // 进入课程 function enterCourse(txtCourseId){ $.ajax({ url: "http://learning.uestcedu.com/learning3/course/enter_in_course.jsp?" + Math.random(), headers : { 'Referer': 'http://learning.uestcedu.com/learning3/uestc_login.jsp?' + Math.random() }, type: "POST", data: { "txtLoginName": "userData.account", "txtPassword": "userData.password", "txtCourseId": txtCourseId, "txtUserType": "student", "txtClassId": "txtClassName", "txtSiteId": GM_getValue("txtSiteId") }, success:function(data){ window.top.location.href = getCoursePage(txtCourseId); } }) }