-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathenaeaHelper.js
166 lines (154 loc) · 6.04 KB
/
enaeaHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// ==UserScript==
// @name enaeaHelper
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author yourself
// @match https://study.enaea.edu.cn/circleIndexRedirect.do*
// @match https://study.enaea.edu.cn/viewerforccvideo.do*
// @grant GM_getValue
// @grant GM_setValue
// @run-at: document-start
// ==/UserScript==
(function() {
'use strict';
var url = window.location.pathname
var checkBtn = setInterval(clickContinueBtn,3000);
var checkFinished = setInterval(awaitPageFinishe,5000);
var checkProgressed = setInterval(checkProgress,3000);
var speed = 4 // 播放速度,建议在2~4
if (url == '/circleIndexRedirect.do' && testUrl('action','toNewMyClass') && testUrl('type','course')) {
sleep(1000).then(() => {
GM_setValue("baseUrl", window.location.href)
var l1 = document.getElementsByClassName("progressvalue")
var l2 = document.getElementsByClassName("golearn ablesky-colortip saveStuCourse")
console.log('进入章节')
for (var i=0;i<l1.length;i++) {
if (l1[i].innerText != '100%'){
sleep(1000).then(()=>{
window.location.href='https://study.enaea.edu.cn' + l2[i].getAttribute("data-vurl")
})
break
}
}
console.log('运行完成')
})
}
if (url == '/viewerforccvideo.do') {
sleep(2000).then(()=>{
// 获取进度
var l1 = document.getElementsByClassName("cvtb-MCK-CsCt-studyProgress")
var l2 = document.getElementsByClassName("cvtb-MCK-CsCt-info clearfix")
var l3 = document.getElementsByClassName("cvtb-MCK-CsCt-title cvtb-text-ellipsis")
console.log(l1, l2, l3)
if (l1.length == 0 && l2.length == 0) {
alert('出错了')
}
for(var i=0;i<l1.length;i++){
if (l1[i].innerText != "100%") {
console.log(l3[i])
l2[i].click()
break
}
}
sleep(300).then(()=>{
var continueBtn = document.getElementById("ccH5jumpInto")
if (continueBtn != null) {
continueBtn.click()
}
})
})
}
function checkProgress(){
//sleep(2000).then(()=>{
var current = document.getElementsByClassName("current cvtb-MCK-course-content")
if (current[0]){
var currentProgress = current[0].getElementsByClassName("cvtb-MCK-CsCt-studyProgress")
if (currentProgress[0] && currentProgress[0].innerText == "100%"){
// 获取进度
var l1 = document.getElementsByClassName("cvtb-MCK-CsCt-studyProgress")
var l2 = document.getElementsByClassName("cvtb-MCK-CsCt-info clearfix")
var l3 = document.getElementsByClassName("cvtb-MCK-CsCt-title cvtb-text-ellipsis")
console.log(l1, l2, l3)
if (l1.length == 0 && l2.length == 0) {
alert('出错了')
}
for(var i=0;i<l1.length;i++){
if (l1[i].innerText != "100%") {
console.log(l3[i])
l2[i].click()
break
}
}
sleep(300).then(()=>{
var continueBtn = document.getElementById("ccH5jumpInto")
if (continueBtn != null) {
continueBtn.click()
}
})
}
}
//})
}
function testUrl(name,value) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == name){
if (pair[1] == value){
return true
} else{
return false
};
}
}
return false;
}
function clickContinueBtn() {
if (url == '/viewerforccvideo.do') {
if ($('video')[0] && $('video')[0].paused){
$('video')[0].muted = true;
$('video')[0].playbackRate = parseInt(speed);
$('video')[0].play()
}else{
$('video')[0].playbackRate = parseInt(speed);
}
if (document.getElementsByClassName("td-content").length != 0){
console.log('找到暂停按钮')
$("button:contains('继续学习')").click();
$(".dialog-content input").click(); // 问答选项
$(".dialog-button-container button").click(); // 问答弹窗
} else {
console.log('未找到暂停按钮')
}
} else {
console.log('非播放界面,不判断是否完成')
}
}
function awaitPageFinishe(){
if (url == '/viewerforccvideo.do') {
var l3 = document.getElementsByClassName("cvtb-MCK-CsCt-studyProgress")
var count = 0;
for(var j=0;j<l3.length;j++){
if (l3[j].innerText != "100%") {
count += 1
}
}
if (count == 0) {
console.log('此章节已完成')
var baseUrl = GM_getValue('baseUrl','')
window.location.href=baseUrl
clearInterval(checkFinished)
clearInterval(checkBtn)
} else{
console.log('章节未完成')
}
} else {
console.log('非播放界面,不判断是否完成')
}
}
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
})();