// ==UserScript==
// @name UESTC积极分子
// @version 0.0.4
// @description UESTC积极分子学习平台刷课工具(修改自YUN积极分子) (作者没学过JS 可能有BUG 请自行修改)
// @author 4ehex + fang
// @match https://dxpx.uestc.edu.cn/jjfz/*
// @match https://dxpx.uestc.edu.cn/exam/*
// @grant unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @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://gf.qytechs.cn/users/896686
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements */
let _self = unsafeWindow, url = location.pathname, videoLists = [], interval_id = -1;
//注册(不可用)油猴菜单
let id_course = RegisterTipMenu("course", "开/关 自动进入未完成课程", "自动进入未完成课程</p><p>(此功能将在进入课程中心时自动查找未完成必读课件的课程)</p>");
let id_compulsory = RegisterTipMenu("compulsory", "开/关 自动进入必修课程", "自动进入必修课程</p><p>(此功能将在进入课程时自动查找未完成的必修课程)</p>");
let id_back = RegisterTipMenu("back", "开/关 自动返回上一级", "自动返回上一级</p><p>(此功能将在完成视频列表里所有播放时, 返回上一级自动查找还未看的视频)</p>");
let id_rightmenu = RegisterTipMenu("rightmenu", "开/关 右键菜单复制", "右键菜单复制</p><p>(此功能将开启右键菜单和复制)</p>");
let id_about = GM_registerMenuCommand ("关于", function(){
video_note();
});
if (GM_getValue("rightmenu")) openCopy();
console.log("[Debug]: " + url);
//定位到'必读课件'<'已完成必读课件'的课程 并自动跳转到'课程中心-精品课程'
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(1, ["关闭"], "提示", '<p>已刷完全部课程</p><p>感谢使用!</p>', 'public_cont1', function () {
$(".public_close").click();
});
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积极分子脚本使用说明", '<p>修改自YNU积极分子</p><p>(我没有学过前端 语法都是现查的 可能有BUG)</p>' +
'<p><font color="aqua"></font>默认功能全关 可点击油猴图标进行设置</p>' +
'<p>本脚本免费使用严谨倒卖</p>',
'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 = '<a href="#" class="public_submit">' + btn_text[0] + '</a>';
} else {
public_a = '<a href="#" class="public_submit">' + btn_text[0] + '</a> <a href="#" class="public_cancel">' + btn_text[1] + '</a>';
}
var public_html = '<div class="public_mask"></div><div class="public_cont ' + public_cont_class + '"><div class="public_title"><h3>' + note_text + '</h3><div class="public_close"></div></div><div class="public_text">' + public_text + '</div><div class="public_btn">' + public_a + '</div></div>';
$("body").append(public_html);
$(".public_close").click(function () {
$(".public_mask").remove();
$(".public_cont").remove();
});
$(".public_mask").click(function () {
$(".public_mask").remove();
$(".public_cont").remove();
});
if (btn_num == 1) {
$(".public_submit").click(function () {
submit_fun();
})
} else {
$(".public_submit").click(function () {
submit_fun();
});
$(".public_cancel").click(function () {
cancel_fun();
})
}
}
function filterImg(dom) {
return $(dom).clone().find("img[src]").replaceWith(function () {
return $("<p></p>").text('<img src="' + $(this).attr("src") + '">');
}).end().find("iframe[src]").replaceWith(function () {
return $("<p></p>").text('<iframe src="' + $(this).attr("src") + '"></irame>');
}).end().text().trim();
}
// 获取url中参数的值
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return (r[2]); return null;
}
// 添加 修改 url中参数的值
function UpdateUrlParam(name, val) {
let thisURL = document.location.href;
// 如果 url中包含这个参数 则修改
if (thisURL.indexOf(name+'=') > 0) {
let v = getUrlParam(name);
if (v != null) {// 是否包含参数
thisURL = thisURL.replace(name + '=' + v, name + '=' + val);
}
else {
thisURL = thisURL.replace(name + '=', name + '=' + val);
}
}
else {// 不包含这个参数 则添加
if (thisURL.indexOf("?") > 0) {
thisURL = thisURL + "&" + name + "=" + val;
}
else {
thisURL = thisURL + "?" + name + "=" + val;
}
}
if (thisURL != document.location.href) document.location.href = thisURL;
};
//注册(不可用)油猴提示菜单
function RegisterTipMenu(id, menu_text, tip_text) {
let id_menu = GM_registerMenuCommand (menu_text, function(){
if (GM_getValue(id)) {
GM_setValue(id, false);
alert_note(1, ["关闭"], "提示", '<p>已关闭 ' + tip_text, 'public_cont1', function () {
$(".public_close").click();
});
}
else {
GM_setValue(id, true);
alert_note(1, ["关闭"], "提示", '<p>已开启 ' + tip_text, 'public_cont1', function () {
$(".public_close").click();
});
}
});
}