// ==UserScript== // @name UESTC dxpx // @version 0.2.2 // @description UESTC dxpx学习平台刷课工具 // @author 4ehex + fang // @match https://dxpx.uestc.edu.cn/user/account/info // @match https://dxpx.uestc.edu.cn/user/lesson // @match https://dxpx.uestc.edu.cn/fzdx/* // @match https://dxpx.uestc.edu.cn/jjfz/* // @match https://dxpx.uestc.edu.cn/exam/* // @connect easylearn.baidu.com // @grant unsafeWindow // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_xmlhttpRequest // @require https://cdn.bootcdn.net/ajax/libs/jquery/2.0.0/jquery.js // @icon http://www.gov.cn/ztzl/17da/183d03632724084a01bb02.jpg // @license MIT // @namespace https://greasyfork.org/zh-CN/users/1073349 // @downloadURL https://update.greasyfork.icu/scripts/465559/UESTC%20dxpx.user.js // @updateURL https://update.greasyfork.icu/scripts/465559/UESTC%20dxpx.meta.js // ==/UserScript== /* globals jQuery, $, waitForKeyElements */ let _self = unsafeWindow, url = location.pathname, videoLists = [], interval_id = -1; //注册油猴菜单 let id_course = RegisterTipMenu("course", "开/关 自动进入未完成课程", "自动进入未完成课程
(此功能将在进入课程中心时自动查找未完成必读课件的课程)
"); let id_compulsory = RegisterTipMenu("compulsory", "开/关 自动进入必修课程", "自动进入必修课程(此功能将在进入课程时自动查找未完成的必修课程)
"); let id_back = RegisterTipMenu("back", "开/关 自动返回上一级", "自动返回上一级(此功能将在完成视频列表里所有播放时, 返回上一级自动查找还未看的视频)
"); let id_rightmenu = RegisterTipMenu("rightmenu", "开/关 右键菜单复制", "右键菜单复制(此功能将开启右键菜单和复制)
"); let id_answer = RegisterTipMenu("answer", "开/关 考试自动搜索答案", "自动搜索答案(此功能将自动读取题目,通过百度题库搜索并显示答案)
") let id_about = GM_registerMenuCommand ("关于", function(){ video_note(); }); // 适配发展对象 if ((url == "/fzdx/lesson")) { alert_note(2, ["转到", "取消"], "[刷课脚本] 提示", '请转到\'个人中心-我的课程\'页面
当前页面还未做刷课适配
', 'public_cont1', function () { $(".public_close").click(); },function (){ $(".public_close").click();}); } if (url == "/user/account/info") { alert_note(2, ["明白", "关闭"], "[刷课脚本] 提示", '发展对象请转到\'我的课程\'页面开始刷课
积极分子请转到\'课程中心\'页面开始刷课
(若未开启刷课,需点击油猴图标开启刷课功能后刷新页面)
', 'public_cont1', function () { window.location.href = "https://dxpx.uestc.edu.cn/user/lesson"; },function (){ $(".public_close").click();}); } if (url == "/user/lesson") { if (!GM_getValue("dont_note")) video_note(); if (GM_getValue("course")) { var unstudy_links = new Array();//所有'未学习'的路由url // 遍历所有 class 为 'study_plan2' 的元素 $('.study_plan2').each(function() { var unfinishedFound = false; // 遍历子元素 $(this).find('*').each(function() { // 检查子元素的文本是否包含 '未完成' if ($(this).text().indexOf('未完成') !== -1) { unfinishedFound = true; return false; // 停止遍历子元素 } }); // 如果找到了包含 '未完成' 的子元素 if (unfinishedFound) { var study_a = $(this).find('.study_a:contains("学习")').attr('href'); unstudy_links.push(study_a); } }); if (unstudy_links.length != 0) { //进入第一个还未学习的课程 console.log("[Debbug] Enter:" + unstudy_links[0]); window.location.href = unstudy_links[0]; } else { alert_note(2, ["好的", "敬请期待"], "提示", '已刷完全部课程
感谢使用!
发展对象考试搜题功能还在开发中^_^
', 'public_cont1', function () { $(".public_close").click();},function (){ $(".public_close").click();}); } } } //定位到'必读课件'<'已完成必读课件'的课程 并自动跳转到'课程中心-精品课程' if (url == "/jjfz/lesson") { if (!GM_getValue("dont_note")) video_note(); if(interval_id!= -1) { clearInterval(interval_id); interval_id = -1; } if (GM_getValue("course")) { let completed_count = 0, course_count = $(".lesson_c_ul").children().length; $(".lesson_center_dl").each( function() { let courseware_ = $(this).text(); let required_ = parseInt(courseware_.substr(courseware_.indexOf("必读课件:") + 5, 4)); let completed_ = parseInt(courseware_.substr(courseware_.indexOf("已完成必读课件:") + 8), 4); //console.log("必读课件:" + required_ + "\n已完成:" + completed_); if (required_ > completed_) {//未完成 $(this).next().children()[0].click();//点击'开始学习' return false; } else{ completed_count += 1; if (completed_count >= course_count) { alert_note(2, ["好的", "关闭刷课功能"], "提示", '已刷完全部课程
感谢使用!
', 'public_cont1', function () { $(".public_close").click(); },function (){ GM_setValue("course", false);GM_setValue("compulsory", false);GM_setValue("back", false); $(".public_close").click(); alert("已关闭 [自动进入未完成课程] [自动进入必修课程] [自动返回上一级]"); }); return false; } } }); } } if (url == "/jjfz/lesson/video" && GM_getValue("compulsory")) { if(interval_id!= -1) { clearInterval(interval_id); interval_id = -1; } //如果URL最后一位是#则删去 if (window.location.href.substr(-1) == "#") { window.location.href = window.location.href.replace(/\#$/, ''); return; } //转到'必修'页面 if (getUrlParam("required") == null || getUrlParam("required") != '1'){ UpdateUrlParam("required", 1); return; } let page_count = 1, page_cur = 1, lesson_cur = 0, completed_cur = 0; //获取有几页课程 (判断.page_btn是否存在) if ($(".page_btn").length != 0) { page_count = $(".page_btn").siblings("a").length - 2;//a标签还有page_go和末页 page_cur = parseInt($(".page_btn").text()); } lesson_cur = $(".lesson1_lists ul:first").children().length; //定位到未完成课程 并自动进入 $(".lesson1_lists ul:first").children().each( function() { if ($(this).find(".lesson_pass").length == 0) {//判断是否有"完成"标志 没有则进入 $(this).children()[0].click(); return false; } else { completed_cur += 1; if (completed_cur >= lesson_cur) {//如果已完成的课程等于列表课程数 则翻页 如果到末页则返回上一级 if (page_cur >= page_count) { console.log("全部已完成,返回课程中心"); if (GM_getValue("back")) $(".head_top_left").find(".head_cut")[0].click(); } else{ UpdateUrlParam("page", page_cur + 1); return false; } } } }); } if ((url.indexOf("jjfz/play") != -1) || (url.indexOf("fzdx/play") != -1)) { let is_fzdx = (url.indexOf("fzdx/play") != -1); getVideoList();//获取视频播放列表 let nextVideoFlag = false, nextClassFlag = false; //不加muted谷歌不让自动播放 setVideoMuted(); interval_id = setInterval(() => { nextVideoFlag = closeAlert(); nextClassFlag = jumpToVideo(videoLists); if (nextVideoFlag) nextClassFlag = nextVideo(videoLists); if (nextClassFlag) { if (is_fzdx){ window.location.href = "https://dxpx.uestc.edu.cn/user/lesson" } else{ goBack(); } } }, 1000) } function getVideoList() { if ($(".video_lists li").length) { //console.log("当前视频" + $(".video_red1").text()) videoLists = $(".video_lists li"); } } function closeAlert(){ if($(".video_red1>a").css("color") == "rgb(255, 0, 0)"){ nextVideo(); }else if($(".public_cont>.public_text>p").text().indexOf('您需要完整观看一遍课程视频') != -1){ $(".public_cont>.public_btn>a")[0].click(); }else if($(".public_cont>.public_text>p").text().indexOf('视频已暂停') != -1){ $(".public_cont>.public_btn>a")[0].click(); }else if($(".public_btn>.public_cancel").text().indexOf('继续观看') != -1 ) { $(".public_btn>.public_cancel")[0].click(); }else if($(".public_cont>.public_text>p").text().indexOf('当前视频播放完毕') != -1){ $(".public_cont>.public_btn>a")[0].click(); }else if($(".public_cont>.public_text>p").text().indexOf('上次观看') != -1){ $(".public_cont>.public_btn>a")[1].click(); }else if($("#wrapper>div>div>button").attr("aria-label") == 'Play'){ $("#wrapper>div>button").click(); } } //判断是否播放完毕过 function isPlayOverEver() { //通过判断Player中是否有进度条来判断是否播放完毕 if ($(".plyr__progress").length) { return true; } else { return false; } } function nextVideo(){ let videoCount = $(".video_lists>ul>li").length; $(".video_lists>ul>li").each((_,element) => { if($(element).children("a").css("color") != "rgb(255, 0, 0)"){//通过文本颜色判断是否播放完毕过 (红色为播放完毕过) $(element).children("a")[0].click() return false }else{ videoCount-- if(videoCount == 0) { console.log("列表播放完毕,返回课程页"); clearInterval(interval_id); goBack(); } } }) } function jumpToVideo(videoList) { if ($(".video_red1").find("a").attr("style") == "width:70%;color:red") { let index = $(videoList).index($(".video_red1")); if (videoList[index + 1]) { $(videoList[index + 1]).children("a").attr('id', 'aRemoveAllTxt'); document.getElementById("aRemoveAllTxt").click(); } else { return true; } } } function goBack() { if (GM_getValue("back")) $('.video_goback')[0].click(); } //给player加上muted标签 function setVideoMuted() { $("#video").prop("muted", true); } //通过'百度教育'搜索答案 if ((url == "/jjfz/lesson/exam" || url == "/jjfz/exam_center/end_exam") && GM_getValue("answer")) { //↓添加一个搜索答案的浮窗 //添加样式 GM_addStyle("body {background: #e9e9e9;font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}.bd_answer {background: #ffffff;position:absolute;box-shadow: 3px 3px 2px grey;}.bd_answer header {background: #bd6982;padding: 10px 15px;color: #ffffff;font-size: 14px;cursor: move;}.bd_answer header:before, .bd_answer header:after {display: block;content: '';clear: both;}.bd_answer header h2, .bd_answer .body ul li .content h3 {margin: 0;padding: 0;font-size: 14px;float: left;}.bd_answer header h2 a {color: #ffffff;text-decoration: none;}.bd_answer header .tools {list-style: none;margin: 0;padding: 0;float: right;}.bd_answer header .tools li {display: inline-block;margin-right: 6px;}.bd_answer header .tools li:last-child {margin: 0;}.bd_answer header .tools li a {color: #ffffff;text-decoration: none;-webkit-transition: all 0.3s linear 0s;-moz-transition: all 0.3s linear 0s;-ms-transition: all 0.3s linear 0s;-o-transition: all 0.3s linear 0s;transition: all 0.3s linear 0s;}.bd_answer .body {position: relative;max-height: 360px;overflow-y: scroll;overflow-x: hidden;}.bd_answer .body .search {display: none;width: 100%;}.bd_answer .body .search.opened {display: block;}.bd_answer .body .search input {width: 100%;margin: 0;padding: 10px 15px;border: none;-webkti-box-size: border-box;-moz-box-size: border-box;box-size: border-box;}.bd_answer .body ul {list-style: none;padding: 0;margin: 0;border-top: 1px solid #f2f2f2;}.bd_answer .body ul li {position: relative;background: #ffffff;display: block;width: 100%;padding: 10px;box-sizing: border-box;}.bd_answer .body ul li:before, .bd_answer .body ul li:after {display: block;content: '';clear: both;}.bd_answer .body ul li:hover .thumbnail {background: #bd6982;}.bd_answer .body ul li:nth-child(2n) {background: #f2f2f2;}.bd_answer .body ul li .thumbnail {display: inline-block;background: #bfbfbf;width: 50px;color: #ffffff;line-height: 50px;text-align: center;text-decoration: none;-webkit-transition: background 0.3s linear 0s;-moz-transition: background 0.3s linear 0s;-ms-transition: background 0.3s linear 0s;-o-transition: background 0.3s linear 0s;transition: background 0.3s linear 0s;}.bd_answer .body ul li .thumbnail img {width: 100%;}.bd_answer .body ul li .content {display: inline-block;margin-left: 6px;vertical-align: top;line-height: 1;}.bd_answer .body ul li .content h3 {display: block;width: 100%;margin-bottom: 5px;color: #808080;}.bd_answer .body ul li .content .preview {display: block;width: 100%;max-width: 200px;margin-bottom: 5px;color: #cccccc;font-size: 12px;}.bd_answer .body ul li .content .meta {color: #b3b3b3;font-size: 12px;}.bd_answer .body ul li .content .meta a {color: #999999;text-decoration: none;}.bd_answer .body ul li .content .meta a:hover {text-decoration: underline;}.bd_answer .body ul li .message {display: none;position: absolute;top: 0;left: 0;overflow: hidden;height: 100%;width: 100%;padding: 10px;box-sizing: border-box;}.bd_answer footer a {background: #bd6982;display: block;width: 100%;padding: 10px 15px;color: #ffffff;font-size: 14px;text-align: center;text-decoration: none;box-sizing: border-box;}.bd_answer footer a:hover {background: #cd8ca0;-webkit-transition: background 0.3s linear 0s;-moz-transition: background 0.3s linear 0s;-ms-transition: background 0.3s linear 0s;-o-transition: background 0.3s linear 0s;transition: background 0.3s linear 0s;}.info {width: 300px;margin: 25px auto;text-align: center;}.info h1 {margin: 0;padding: 0;font-size: 20px;font-weight: 400;color: #333333;}.info span {color: #666666;font-size: 12px;}.info span a {color: #000000;text-decoration: none;}.info span .fa {color: #bd6982;}.info span .spoilers {color: #999999;margin-top: 5px;font-size: 10px;}"); //添加html $("body").prepend(`[*] 默认功能全关 需点击油猴图标进行设置
' + '[*] 积极分子开启前三项即可自动刷课
' + '[*] 发展对象只需开启第一项和第三项
' + '[+] 新增发展对象刷课功能
' + '[-] 考试自动搜题功能已失效 之后完善
', 'public_cont1', function () { $(".public_close").click(); //此为关闭方法 GM_setValue("dont_note", false) }, function () { $(".public_close").click(); //此为关闭方法 GM_setValue("dont_note", true) }); } function alert_note(btn_num, btn_text, note_text, public_text, public_cont_class, submit_fun, cancel_fun) { var public_a; if (btn_num == 1) { public_a = '' + btn_text[0] + ''; } else { public_a = '' + btn_text[0] + ' ' + btn_text[1] + ''; } var public_html = '已关闭 ' + tip_text, 'public_cont1', function () { $(".public_close").click(); }); } else { GM_setValue(id, true); alert_note(1, ["关闭"], "提示", '
已开启 ' + tip_text, 'public_cont1', function () {
$(".public_close").click();
});
}
});
}
//以同步方式发送跨域请求
function SyncXmlHttpRequest(request_url, method_type) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: method_type,
url: request_url,
headers: {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"
},
onload: function(response) {
if (response.status != 200){
return reject("Search GET response Not 200 OK!");
}
//console.log("[Debug] " + response.responseText);
return resolve(response.responseText);
},
onerror: function(err) {
return reject(err);
}
});
});
}
//纯字符串操作的方式 删去答案和选项中html标签中的杂项
function DelMiscContent(val){
let start = -1, end = -1, pos = -1, ele = "div";
while((pos = val.indexOf('text-indent')) != -1){
start = val.lastIndexOf('<', pos);
ele = val.substring(start + 1, val.indexOf(" ", start));
if (val.indexOf("/>", pos) != -1){
end = val.indexOf("/>", pos) + 2;
}
else{
end = val.indexOf("" + ele, pos) + 6;
}
val = val.substring(0, start) + val.substr(end);
}
return GetPlainText(val);
}
//去除文本中的html标签
function GetPlainText(val) {
if (val != null && val != "") {
var re1 = new RegExp("<.+?>|&.+?;","g"); //匹配html标签的正则表达式,"g"是搜索匹配多个符合的内容
var msg = val.replace(re1,""); //执行替换成空字符
msg = msg.replace(/\s/g,""); //去掉所有的空格(中文空格、英文空格都会被替换)
msg = msg.replace(/[\r\n]/g,""); //去掉所有的换行符
return msg;
} else return ''
}
//获取中的src的值
function GetImgSrc(article) {
let reg = /(< img|
|\/>)/gim //匹配所有图片标签
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i // 匹配图片中的src
return article.match(reg).map(val => {
let src = val.match(srcReg)
return src[1]
});
}