// ==UserScript== // @name UESTC积极分子 // @version 0.0.9 // @description UESTC积极分子学习平台刷课工具 // @author 4ehex + fang // @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 none // ==/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 == "/jjfz/lesson/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(); },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) { getVideoList();//获取视频播放列表 let nextVideoFlag = false, nextClassFlag = false; //不加muted谷歌不让自动播放 setVideoMuted(); interval_id = setInterval(() => { nextVideoFlag = closeAlert(); nextClassFlag = jumpToVideo(videoLists); if (nextVideoFlag) nextClassFlag = nextVideo(videoLists); if (nextClassFlag) 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_play1").attr("muted"); } function openCopy() { $(document).ready(new function () { document.oncontextmenu = new Function("event.returnValue=true"); document.onselectstart = new Function("event.returnValue=true"); document.oncopy = new Function("return true"); }) } function video_note() { alert_note(2, ["关闭", "不再提示"], "UESTC积极分子脚本使用说明", '修改自YNU积极分子
(我没有学过前端 语法都是现查的 可能有BUG)
' + '默认功能全关 可点击油猴图标进行设置
' + '本脚本免费使用严谨倒卖
', '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 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]
});
}