// ==UserScript==
// @name 四川电子科大刷课脚本
// @namespace http://tampermonkey.net/
// @version 0.9
// @description 四川电子科大刷课简易脚本,网教与学堂云两个平台均支持,脚本并不完善可能存在问题,欢迎在评论区留言帮助作者改善脚本
// @author Cribug
// @license MIT
// @match https://uestcedu.yuketang.cn/pro/lms/*
// @match http://learning.uestcedu.com/*
// @grant none
// @noframes
// ==/UserScript==
(function() {
// Your code here...
//创建弹窗
(function(){
var div = document.createElement('div');
div.id = "cribug";
div.innerHTML = `<div class="cribug-pop" style="position:fixed;right:17px;bottom:30px;width:400px;height:500px;border-radius:3px 0 0 0;border-left:3px solid #333;border-top:3px solid #333;background:#fff;transition:all .2s ease;z-index:999;">
<div class="cribug-title" style="position:relative;background:#ccc;line-height:40px;color:#333;text-indent:6px">电子科大刷课脚本 <button class="cribug-open">支持作者</button><div class="cribug-switch" style="position:absolute;right:15px;top:10px;width:16px;height:20px;"><i style="display:block;width:100%;height:2px;margin-top:9px;background:#333;"></i></div></div>
<div class="cribug-importantInfo" style="padding-left:6px;color:red;height:30%;border-bottom:1px solid #333;overflow:auto;">
<p>注意:当前脚本完全开源免费,如果你从任何途径购买了本脚本,请要求对方退费!有问题欢迎在Greasy Fork评论反馈。</p>
</div>
<div class="cribug-journal" style="height:calc(70% - 41px);padding-left:6px;overflow:auto;"></div>
</div>
<div class="cribug-sponsor" style="display:none;position:fixed;left:50%;top:50%;width:100%;height:100%;transform:translate(-50%,-50%);background:rgba(0,0,0,.4);z-index:999;">
<div style="margin:200px auto 0;width:500px;height:300px;padding:20px;background:#fff;border-radius:5px;border:2px solid #333">
感谢您对作者的支持!<br />您的打赏能够有效加快脚本的完善!
<div style="display:flex;justify-content:center;margin-top:25px;width:100%;">
<div>
<div style="width:100%;text-align:center;">微信</div>
<img src="https://www.helloimg.com/images/2022/05/26/ZaZDZQ.th.jpg">
</div>
<div style="margin-left:20px">
<div style="width:100%;text-align:center;">支付宝</div>
<img src="https://www.helloimg.com/images/2022/05/26/ZaZcy1.th.jpg">
</div>
</div>
<button class="cribug-shut" style="margin:30px auto;display:block;">关闭</button>
</div>
</div>`
var bob = document.querySelector('body');
bob.appendChild(div)
//打赏页面开关
var open = document.getElementsByClassName("cribug-open")[0];
var shut = document.getElementsByClassName("cribug-shut")[0];
var spomsor = document.getElementsByClassName("cribug-sponsor")[0];
open.onclick = function(){spomsor.style.display = "block"};
shut.onclick = function(){spomsor.style.display = "none"};
//弹窗最小化,最大化
var switc = document.getElementsByClassName("cribug-switch")[0];
var pop = document.getElementsByClassName("cribug-pop")[0];
switc.onclick = function(){
if(pop.style.transform != "translateY(490px)"){
pop.style.transform = "translateY(490px)"
}else{
pop.style.transform = "translateY(0)"
}
}
})();
//日志输出
var importantInfo = document.getElementsByClassName("cribug-importantInfo")[0];
var journal = document.getElementsByClassName("cribug-journal")[0];
function output(position,text){
var p = document.createElement('p');
p.innerHTML = text;
position.appendChild(p)
position.scrollTop = position.scrollHeight;
};
//等待页面加载完毕判断当前运行的平台
window.onload = function(){
output(importantInfo,"页面加载完成,脚本即将启动")
setTimeout(document.location.protocol == "https:" ? xty:wj,2000)
}
// var js = 0
// var elevideo = document.getElementsByClassName("xt_video_player")[0];
// function videoEvent(){
// //暂停视频,显示
// elevideo.pause()
// //静音
// document.getElementsByClassName("xt_video_player_common_icon")[0].click();
// //2X播放
// var playSpeedDiv = document.getElementsByClassName("xt_video_player_common_list_wrap")[1];
// playSpeedDiv.style.cssText = "display:block;opacity:1;";
// setTimeout(function(){
// console.log(playSpeedDiv.getElementsByTagName("li")[0])
// playSpeedDiv.getElementsByTagName("li")[0].click();
// elevideo.removeEventListener('play',videoEvent)
// },1000)
// }
// var zt = setInterval(function(){
// elevideo = document.getElementsByClassName("xt_video_player")[0];
// if(elevideo && js<20){
// elevideo.addEventListener('play',videoEvent)
// clearInterval(zt)
// }
// js++
// console.log(js)
// },500)
function xty(){
//获取video元素、video外层的div、作业页面的元素,用于判断当前处于哪个页面
var elevideo = document.getElementsByClassName("xt_video_player")[0];
var idVideo = document.getElementById("video-box");
var zy = document.getElementsByClassName("container-body")[0];
//处理地址
var url = window.location.href;
var urlSplit = url.split('video/');
var newUrl = urlSplit[0] + "video/" + (Number(urlSplit[1])+1);
//判断当前页面状态
if(elevideo){
output(importantInfo,"当前为学堂云平台,脚本运行中...")
output(importantInfo,"请注意,脚本可能会切换章节出错,需要手动介入")
output(importantInfo,`当前时间:${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`);
//监听视频是否播放完毕
elevideo.addEventListener('ended',function(){
output(journal,"视频已播放完毕,即将切换到下一课件...")
setTimeout(function(){window.location.href = newUrl},3000)
})
}else if(idVideo){
output(importantInfo,"脚本已跳转到不正确的地址,请手动介入:点击右上角目录,手动切换到未学习的课节,脚本将自动运行");
output(importantInfo,`脚本已暂停,当前时间:${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`);
}else if(zy){
output(importantInfo,"当前为学堂云平台作业页面,自动答题中...")
output(importantInfo,"目前仅支持单选题")
//答题序号列表的li
var numberList = document.getElementsByClassName("exam-aside--close")[0].getElementsByTagName("li");
//提交答案按钮
var btn = document.getElementsByClassName("text-center")[0].getElementsByTagName("button")[0];
var i = 0;
//答题逻辑(代码有点烂,层层套娃,技术有限)
function answer(){
if(i < numberList.length){
numberList[i].getElementsByTagName("div")[0].click();
setTimeout(function(){
//题目答案列表
var daan = document.getElementsByClassName("list-unstyled")[0].getElementsByTagName("li");
var z = 0;
function answer2(){
if(numberList[i].getElementsByTagName("svg").length){
output(journal,`第${i+1}题已回答正确,进入下一题`);
i++;
z = 0;
answer();
}else{
setTimeout(function(){
daan[z].getElementsByTagName("label")[0].click();
z++;
},1000)
setTimeout(function(){btn.click()},1500)
setTimeout(function(){answer2()},4000)
}
}
answer2();
},1000)
}else{
output(journal,"所有题目回答完毕,即将进行跳转...")
setTimeout(function(){window.location.href = newUrl},3000)
}
}
answer();
}else{
output(importantInfo,"当前为学堂云平台,未进入学习或作业页面,等待中...")
}
//监听地址栏变化
var dsq = setInterval(function(){
var nUrl = window.location.href;
if(nUrl != url){
output(importantInfo,"用户已手动切换课件,脚本即将重新启动...")
clearInterval(dsq)
setTimeout(xty,10000)
}
},3000)
}
function wj(){
var btn = document.getElementsByName("w_main")[0].contentWindow.document.getElementById("w_code");
if(btn){
var btn2 = btn?.contentWindow?.document?.getElementById("tdPlayerControl")?.childNodes;
if(btn2 == undefined){
return setTimeout(wj,2000);
}
output(importantInfo,"当前为网教平台,脚本运行中...")
var btnPrev = btn2[1];
var btnNext = btn2[3];
var wjdsq = null;
var vChange = NaN;
function fn(speed){
var v = vChange;
wjdsq = setInterval(function(){
//看看这一长串,真的是比俄罗斯套娃还能套
var isxx = document.getElementsByName("w_main")[0].contentWindow.document.getElementById("w_lms_content").contentWindow.document.getElementsByTagName("tr")[1].getElementsByTagName("td")[0].innerHTML.indexOf("已经学习完毕");
if(isxx > 0){
btnNext.click();
output(journal,`已自动切换下一课件,当前时间:${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`)
if(v == vChange && document.visibilityState == "visible"){
output(importantInfo,"页面已重回前台台,恢复正常模式")
clearInterval(wjdsq)
return fn(90)
}
}else{
btnNext.click();
setTimeout(function(){btnPrev.click()},500)
if(speed > 20){
output(importantInfo,`当前课件计时疑似出错,将进行重试,当前时间:${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`);
if(v == vChange && document.visibilityState == "hidden"){
output(importantInfo,"页面可能已置于后台,启用激活模式")
clearInterval(wjdsq)
return fn(20)
}
}
}
},1000*speed)
};
fn(90);
document.addEventListener('visibilitychange',function(){
if(document.visibilityState == "visible"){
vChange = "v"
}else if(document.visibilityState == "hidden"){
vChange = "h"
}
})
}else{
output(importantInfo,"当前为网教平台,未进入学习界面,等待中...")
var list = document.getElementsByName("w_main")[0].contentWindow.document.getElementById("frame_learning_content_1").getElementsByTagName("a");
for(var a of list){
a.addEventListener("click",function(){
return setTimeout(wj,3000)
})
}
}
}
//根据协议名判断是哪个平台,设置延时器是防止页面未加载完成导致脚本出错(弃用,使用onload代替)
//setTimeout(document.location.protocol == "https:" ? xty:wj,10000)
})();