学校要求每个学习单位都学习45分钟,一共28个单位——
但是挂机时候发现5分钟没操作,就会弹框提示而且制止累积学习时长。刚刚开始以为是检测点击,究竟通例思绪,用了鼠标连点器,还是不可,于是举行了研究。
[C#] 纯文本查看 复制代码前面的都是整体框架,显示模式,格式控制等等,直接省略。 //check whether the material has been authorized to the student function CheckAuthorize(material) { //检测用户信息是否授权利用,必要正版课本附赠的激活码才气利用全部课程 var res = false; $.ajax({ url: "Student/LogTime.aspx", async: false, datatype: "html", data: "logType=checkneedauthorize&material=" + material + "&nocache=" + Math.random(), success: function (result) { if (result != "false") { document.getElementById("spMaterialAuth").style.display = ""; document.getElementById("spMaterialName").innerText = result; var returnvalue = window.showModalDialog("Student/MaterialAuth.aspx?material=" + material, null, "dialogWidth=800px;dialogHeight=300px"); if (returnvalue && (returnvalue == "passed" || returnvalue == "submited")) { res = true; document.getElementById("spMaterialAuth").style.display = "none"; } } else { document.getElementById("spMaterialAuth").style.display = "none"; res= true; } } }); return res; } //script block for study time stat //TODO 此方法和StartNewStatTime没区别,仅在服务器端处理有些许区别,应该合并。 function AddStatTime(stattype, url){ var material = ""; var unit = ""; var classno = ""; // is study material var ret = IsMaterialStudyUrl(url); if (ret != "false") { var info = ret.split('|'); classno = info[0]; material = info[1]; unit = info[2]; } else { ret = IsAssistStudyUrl(url); if (ret != "false") { var info = ret.split('|'); material = info[0]; unit = info[1]; } } $.ajax({ url: "Student/LogTime.aspx", async: false, datatype: "html", data: "logType=addstattime&stattype="+stattype+"&material="+material+"&unit="+unit+"&class="+classno+"&nocache="+Math.random(), success: function(result) { } }); } function EndStatTime(){ //判定为挂机行为的后续操作,踢出在线状态 $.ajax({ url: "Student/LogTime.aspx", async: false, datatype: "html", data: "logType=endstattime"+"&nocache="+Math.random(), success: function(result) { } }); } function UpdateStatTime(){ //累积在线时长 $.ajax({ url: "Student/LogTime.aspx", async: false, datatype: "html", data: "logType=updatestattime"+"&nocache="+Math.random(), success: function(result) { } }); } function StartNewStatTime(stattype, url){ var material = ""; var unit = ""; var classno = ""; // is study material var ret = IsMaterialStudyUrl(url); if (ret != "false") { var info = ret.split('|'); classno = info[0]; material = info[1]; unit = info[2]; } else { ret = IsAssistStudyUrl(url); if (ret != "false") { var info = ret.split('|'); material = info[0]; unit = info[1]; } } $.ajax({ url: "Student/LogTime.aspx", async: false, datatype: "html", data: "logType=startnewstattime&stattype="+stattype+"&material="+material+"&unit="+unit+"&class="+classno+"&nocache="+Math.random(), success: function(result) { } }); } //计时,每一分钟累积一次在线时长。 function CountSeconds() { try{ CheckToken(); }catch(e){} if (!isTest){ seconds++; if (seconds >= 60) { //one minutes UpdateStatTime(); seconds = 0; } } } var secTimerID = window.setInterval("CountSeconds();", 1000); function GetRandomWord() { var res = false; $.ajax({ url: "Student/LogTime.aspx", async: false, datatype: "html", data: "logType=getrandomword&nocache=" + Math.random(), success: function (result) { res = result; } }); return res; } function Leave() //判定为挂机行为后,弹出提示 { var msg = GetRandomWord(); var loadingInfo = '离开了?返来学个单词吧。
'+msg+'
'; TINY.box.show({html:loadingInfo,mask:true,animate:false,close:true,boxid:'frameless',closejs:function(){LeaveBack()}}); } function LeaveBack()//点击离开提示后,再次开始累积 { seconds = 0; AddStatTime("", window.frames['mainFrame'].document.location.href); GetServerTime("StudyStart"); MoveMouse(); secTimerID = window.setInterval("CountSeconds();", 1000); actTimerID = window.setInterval("CheckActive();", 5000); } function CheckActive() { //检测是否是挂机。如果超过5分钟没有鼠标在网页上移动,就判定为挂机,好比可能最小化了再玩别的游戏 if (!isMaterialStudy && !isAssistStudy) return; var d = new Date(); if (d.getTime() - latestMoveTime > 300 * 1000) { clearInterval(actTimerID); clearInterval(secTimerID); EndStatTime(); Leave(); } } var actTimerID = window.setInterval("CheckActive();", 5000); function MainFrameClick(){ MoveMouse(); } function newResize() { var subwindow=window.frames[0]; if(subwindow && subwindow.Resize) subwindow.Resize(); } |