挂机插件提醒您:本课程最少需学习:" + 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('查找还未读完的课程', {offset: 'b'});
if($("div[name*=frame_learning_content_] #tblDataList").length == 0 || $("#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('挂机插件正常工作中,莫慌张....', {offset: 'b'});
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){
layer.msg("第" + ++window.errorCount + "次检测到学习时间没发生变化(这是学习平台自身的BUG,过一会就好了。如持续5次未检测到变化,将刷新页面重试)" + aa, {time: 10000})
if(window.errorCount >= 5){
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.clearTimeout(timeoutIndex);
fun();
}, time);
layer.confirm(content, {icon: 3, title:'提示'}, function(index){
window.clearTimeout(timeoutIndex);
fun();
layer.close(index);
}, function(index){
window.clearTimeout(timeoutIndex);
if(fun2 != undefined){
fun2();
}
});
}
// 监听登录状态
function monitorLogin(){
console.log("监听登录状态");
layer.msg('监听登录状态', {offset: 'b'});
if(!validLogin()){
var userData = GM_getValue("userData");
if(!userData || !userData.account){
layer.confirm('无效登录状态。本地没有您的账号信息,无法完成自动登录,需要进行手动登录?', {icon: 3, title:'提示'}, function(index){
window.location.href = "https://student.nxu.com/console/";
});
}else{
autoConfirm(3000, '无效登录状态,正在尝试自动登录?(3秒后无操作,将默认尝试登录)', function(){
var url = login(userData, userData.data.courseId);
window.location.href = url;
});
}
}
setTimeout(monitorLogin, 1000 * 60); // 1分监听一次登录状态
}
// 校验网络学习平台登录状态
function validLogin(){
var login = true;
$.ajax({
url: GM_getValue("baseLearningUrl") + "/json/login_info.jsp",
async: false,
dataType:"json",
success:function(data){
if(data.username === ''){
console.log("无效登录状态");
login = false;
}else{
layer.msg('定时检测登录状态:当前登录状态有效', {offset: 'b'});
}
},
error:function(){
layer.alert('网络学习平台繁忙,检测登陆状态失败!', {icon: 3, title:'提示'}, function(index){
layer.close(index);
});
}
})
return login;
}
// 登录网络学习平台
function login(userData, courseId){
var url = GM_getValue("baseLearningUrl") + "/uestc_login.jsp?" + Math.random();
url += "&txtLoginName=" + userData.account;
url += "&txtPassword=" + userData.password;
url += "&txtCourseId=" + courseId;
url += "&txtUserType=" + userData.data.userType;
url += "&txtClassId=" + userData.data.classId;
url += "&txtClassName=" + userData.data.className;
url += "&txtSiteId=" + userData.data.siteId;
return url; // 返回登录url(登录后会自动跳转到课程)
/*
// 去除以前旧的登录方式
$.ajax({
url: GM_getValue("baseLearningUrl") + "/uestc_login.jsp?" + Math.random(),
type: "get",
data: {
"txtLoginName": userData.account,
"txtPassword": userData.password,
"txtCourseId": userData.data.courseId,
"txtUserType": userData.data.userType,
"txtClassId": userData.data.classId,
"txtClassName": userData.data.className,
"txtSiteId": userData.data.siteId
},
timeout: 3000,
success: function (data) {
$.ajax({
url: GM_getValue("baseLearningUrl") + "/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': GM_getValue("baseLearningUrl") + '/'
},
type: "POST",
data: {
"txtLoginName": userData.account,
"txtPassword": userData.password,
"txtCourseId": userData.data.courseId,
"ran": Math.random()
},
timeout:3000,
success:function(data){
console.log(data);
var body = document.getElementsByTagName("body");
var div = document.createElement("div");
div.innerHTML = '';
document.body.appendChild(div)
window.location.reload();
},
error:function(){
layer.alert('网络学习平台繁忙,无法帮你完成登录,请稍后再试!', {icon: 3, title:'提示'}, function(index){
layer.close(index);
});
}
})
},
error: function () {
layer.alert('网络学习平台繁忙,无法帮你完成登录,请稍后再试!', {icon: 3, title: '提示'}, function (index) {
layer.close(index);
});
}
})*/
}
// 获取当前窗口相对路径
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: GM_getValue("baseLearningUrl") + "/course/enter_in_course.jsp?" + Math.random(),
headers : {
'Referer': GM_getValue("baseLearningUrl") + '/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);
}
})
}
function checkIfTheCoursePageIsLoaded(){
var mainWin = $("iframe[name=w_main]")[0].contentWindow;
if(mainWin.document.body.innerHTML == ""){
layer.alert('课程加载失败');
}
/*var mainWin = $("iframe[name=w_main]")[0].contentWindow;
if (mainWin.document.getElementsByTagName("body").length == 0) {
layer.load(0, {shade: false});
}*/
}
// 显示作者信息
function openOtherInfo(){
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['420px', '560px'], //宽高
offset: 'rb',
shade :0,
content: '不要相信这里显示内容,否则后果自负' +
'

' +
'

' +
'
'
});
}
function timedRefresh(){
if (window.location == parent.location) {
setInterval(function () {
autoConfirm(10000, '您已挂机5分钟。为防止页面长时间执行引起的各种小问题的出现,将为您自动刷新页面(10秒后无操作,将默认刷新)', function(){
window.location.reload();
});
}, 1000 * 60 * 5);
}
}
// 学堂在线:登录学堂在线系统
function xl_login(sLearningCourseId, sExamCode) {
var sUrl = "https://student.nxu.com/rs/loginCheck/yuketang";
var sData = {
course_id: sLearningCourseId,
exam_code: sExamCode,
ran: Math.random()
}
var url;
$.ajax({
url: sUrl,
data: sData,
async: false,
type: "POST",
success: function (json) {
if (!json.success) {
alert(json.message);
} else {
url = json.message;
}
}
});
return url;
}
// 学堂在线:进入章节目录,开始学习课程
function xl_startLearn(){
autoConfirm(10000, '是否开始学习所有章节下的课程?(10秒后无操作,将默认学习)
说明:插件将打开多个子窗口,对本章节下所有课程执行学习!', function(){
layer.msg('执行自动学习', {offset: 'b'});
var vue = document.querySelector('[data-v-3d8fef40]').__vue__;
var chapterList = vue.$data.chapter_list; // 所有章节目录
var leafList = new Array(); // 所有课程
// 收集课程
function collectLeaf(chapterList, leafList, partnerChapter) {
for (const chapter of chapterList) {
chapter.partnerChapter = partnerChapter;
if (chapter.leafinfo_id) { // 说明是课程
if (chapter.leaf_type != 6) { // 暂时不计入习题
leafList.push(chapter);
}
} else {
var childList = chapter.section_leaf_list || chapter.leaf_list; // 存在子节点,继续递归
if (childList) {
collectLeaf(childList, leafList, chapter);
}
}
}
}
collectLeaf(chapterList, leafList);
console.log("所有课程:" , leafList)
// 获取所有未学习完成的课程
function getNotSuccessLeafList() {
var leafSchedules = vue.$data.leaf_schedules; // 所有课程完成情况
var notSuccessLeafList = leafList.filter(leaf => leafSchedules[leaf.id] == null || leafSchedules[leaf.id] < 1);
console.log("所有未完成的课程:", notSuccessLeafList);
return notSuccessLeafList;
};
// 学习课程
function learningCourses(notSuccessLeafList){
var sign = vue.$data.sign;
var classroomId = vue.$data.classroom_id; // 教堂ID
window.learningCourse = window.learningCourse || new Object(); // 学习中的课程
for (const notSuccessLeaf of notSuccessLeafList) {
var leafOpenCount = Object.keys(window.learningCourse).length;
var openSize = 1; // 同时学习多少个课程。配置太多可能会不计学时
if (leafOpenCount < openSize && !window.learningCourse.hasOwnProperty(notSuccessLeaf.id)) {
window.learningCourse[notSuccessLeaf.id] = notSuccessLeaf;
setTimeout(function () {
console.log(notSuccessLeaf)
let title = "";
let notSuccessLeafTemp = notSuccessLeaf;
while (notSuccessLeafTemp.partnerChapter) {
notSuccessLeafTemp = notSuccessLeafTemp.partnerChapter;
title = "【" + notSuccessLeafTemp.name + "】 - " + title;
}
title = "正在学习课程:" + title + "【" + notSuccessLeaf.name + "】";
layer.open({
title: title,
type: 2,
shade: false,
area: '500px',
maxmin: true,
offset: [
Math.random() * ($(window).height() - 300),
Math.random() * ($(window).width() - 800)
],
content: 'https://nxu.yuketang.cn/pro/lms/' + sign + '/' + classroomId + '/video/' + notSuccessLeaf.id,
zIndex: layer.zIndex,
success: function (layero) {
layer.setTop(layero);
},
end: function () {
delete window.learningCourse[notSuccessLeaf.id];
}
});
}, leafOpenCount * 3000);
}
}
};
// 扫描并学习没有学过的课程
const scanAndLearning = function () {
// 重新获取一次最新的学习进度
xl_getLearnSchedule();
// 获取未读完的课程
var notSuccessLeafList = getNotSuccessLeafList();
if (notSuccessLeafList) {
// 开始学习所有没有读的课程
learningCourses(notSuccessLeafList);
} else {
clearInterval(scanLeafInterIndex);
layer.alert('本章节课程已全部学习完毕', {icon: 3, title: '提示'}, function (index) {
layer.close(index);
});
}
return scanAndLearning;
};
var scanLeafInterIndex = setInterval(scanAndLearning(), 1000 * 30);
});
}
// 学堂在线:章节目录页面,重新获取学习进度
function xl_getLearnSchedule(){
layer.msg('插件正在加载章节最新学习进度....', {offset: 'b'});
document.querySelector('[data-v-3d8fef40]').__vue__.getLearnSchedule();
}
// 学堂在线:学习课程视频
function xl_learnVideo() {
clearAllInterval();
var intervalIndex = setInterval(function () {
layer.msg('扫描课程学习进度', {offset: 'b'});
var rate = document.querySelector('[data-v-6e71ac7e]').__vue__.$data.rate; // 课程学习情况
if (rate >= 1) {
clearInterval(intervalIndex);
if (unsafeWindow.parent.layer && unsafeWindow.parent.layer.getFrameIndex(window.name)) {
autoConfirm(3000, '本课程已学习完毕,是否关闭子窗口?(3秒后无操作,将默认关闭)', function () {
var index = unsafeWindow.parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
unsafeWindow.parent.layer.close(index); //再执行关闭
});
} else {
layer.alert('本课程已学习完毕', {icon: 3, title: '提示'}, function (index) {
layer.close(index);
});
}
}
}, 1000 * 10); //扫描课程学习情况
// 修改倍数
autoConfirm(3000, '是否修改课程学习倍数?(3秒后无操作,将默认执行修改)', function(){
var videoIntervalIndex = setInterval(function () {
var player = document.querySelector('[data-v-2259ff49]').__vue__.$data.player;
if (player != null) {
clearInterval(videoIntervalIndex);
$(".xt_video_player_common_active").removeClass("xt_video_player_common_active");
var $li = $(".xt_video_player_common_list li :first");
var speed = 3.6; // 倍数(如果学习进度不更新,把这里改回1倍数)
var speedText = "插件:" + speed + "X";
$li.text(speedText);
$li.attr("keyt", speed);
$li.addClass("xt_video_player_common_active");
$li[0].dataset.speed = speed;
var $speedPlayerCommon = $(".xt_video_player_speed .xt_video_player_common_value");
$speedPlayerCommon.text(speedText);
$(".xt_video_player_speed").mouseout();
$li[0].click();
// 处理静音
$(".xt_video_player_common_icon").click();
$("video")[0].muted = true;
player.video.muted = true;
// 处理自动播放
var payIntervalIndex = setInterval(function () {
if (player.video.play != null) {
clearInterval(payIntervalIndex);
player.video.play(); // 强制播放视频
//player.$video.off("timeupdate.speed");
player.$video.on("timeupdate.speed", function () {
player.options.speed.value = speed;
player.video.playbackRate = speed;
$speedPlayerCommon.text(speedText);
player.video.play(); // 强制播放视频
});
}
}, 500);
} else {
layer.msg('等待视频加载....', {offset: 'b'});
//window.location.reload(); // 视频没加载到,刷新页面
}
}, 500);
});
}