@@ -8,12 +8,81 @@ class Course {
8
8
class CommonCourse extends Course {
9
9
10
10
start ( ) {
11
- if ( ! hasCourseNeedCountinue ( ) ) {
11
+ if ( ! this . hasCourseNeedCountinue ( ) ) {
12
12
notifyFinish ( )
13
13
return
14
14
}
15
15
startCourse ( )
16
- checkSituation ( )
16
+ this . checkSituation ( )
17
+ }
18
+
19
+ parseInnerDom ( item ) {
20
+ // return item.lastElementChild.lastElementChild
21
+ return item . lastElementChild . children [ 1 ]
22
+ }
23
+
24
+ isCompleted ( status ) {
25
+ return status === '重新学习' || status === '已完成'
26
+ }
27
+
28
+ hasCourseNeedCountinue ( ) {
29
+ const lists = Array . from ( document . getElementsByClassName ( 'chapter-list-box' ) )
30
+ const needCoutinue = lists . some ( item => {
31
+ const innerDom = this . parseInnerDom ( item )
32
+ const type = innerDom . firstElementChild . innerHTML
33
+ const status = innerDom . lastElementChild . lastElementChild . innerHTML
34
+ return ( type === '视频' || type === '文档' ) && ! this . isCompleted ( status )
35
+ } )
36
+ return needCoutinue
37
+ }
38
+
39
+ checkSituation ( ) {
40
+ const taskId = setInterval ( ( ) => {
41
+ const needCoutinue = this . hasCourseNeedCountinue ( )
42
+ if ( ! needCoutinue ) {
43
+ clearInterval ( taskId )
44
+ notifyFinish ( )
45
+ } else {
46
+ this . changeVideoIfNecessary ( )
47
+ }
48
+ const node = currentNode ( )
49
+ const courseName = node . getElementsByClassName ( 'text-overflow' ) [ 0 ] . innerText
50
+ window . document . title = `🔵正在播放【${ courseName } 】`
51
+ } , 1000 )
52
+ }
53
+
54
+ changeVideoIfNecessary ( ) {
55
+ if ( this . currentFinish ( ) ) {
56
+ const nextCourse = Array . from ( document . getElementsByClassName ( 'chapter-list-box' ) ) . filter ( item => {
57
+ const innerDom = this . parseInnerDom ( item )
58
+ const type = innerDom . firstElementChild . innerHTML
59
+ const status = innerDom . lastElementChild . lastElementChild . innerHTML
60
+ return ( type === '视频' || type === '文档' ) && ! this . isCompleted ( status )
61
+ } ) . shift ( )
62
+ if ( nextCourse ) {
63
+ nextCourse . click ( )
64
+ setTimeout ( ( ) => {
65
+ startCourse ( )
66
+ } , 1000 ) ;
67
+ }
68
+ } else {
69
+ //有些电脑太卡,初始化时播放不了,用于兜底
70
+ startCourse ( )
71
+ }
72
+ }
73
+
74
+ currentFinish ( ) {
75
+ const itemDom = this . parseInnerDom ( currentNode ( ) )
76
+ const type = itemDom . firstElementChild . innerHTML
77
+ const status = itemDom . lastElementChild . lastElementChild . innerHTML
78
+ return ( this . isCompleted ( status ) ) || ( type === '考试' && status !== '参与考试' )
79
+ }
80
+ }
81
+
82
+ class RenbaoCourse extends CommonCourse {
83
+
84
+ parseInnerDom ( item ) {
85
+ return item . lastElementChild . children [ 1 ]
17
86
}
18
87
}
19
88
@@ -43,59 +112,6 @@ const currentNode = () => {
43
112
return document . getElementsByClassName ( 'chapter-list-box focus' ) [ 0 ]
44
113
}
45
114
46
- const currentFinish = ( ) => {
47
- const itemDom = currentNode ( ) . lastElementChild . lastElementChild
48
- const type = itemDom . firstElementChild . innerHTML
49
- const status = itemDom . lastElementChild . lastElementChild . innerHTML
50
- return ( status === '重新学习' ) || ( type === '考试' && status !== '参与考试' )
51
- }
52
-
53
- const changeVideoIfNecessary = ( ) => {
54
- if ( currentFinish ( ) ) {
55
- const nextCourse = Array . from ( document . getElementsByClassName ( 'chapter-list-box' ) ) . filter ( item => {
56
- const innerDom = item . lastElementChild . lastElementChild
57
- const type = innerDom . firstElementChild . innerHTML
58
- const status = innerDom . lastElementChild . lastElementChild . innerHTML
59
- return ( type === '视频' || type === '文档' ) && status !== '重新学习'
60
- } ) . shift ( )
61
- if ( nextCourse ) {
62
- nextCourse . click ( )
63
- setTimeout ( ( ) => {
64
- startCourse ( )
65
- } , 1000 ) ;
66
- }
67
- } else {
68
- //有些电脑太卡,初始化时播放不了,用于兜底
69
- startCourse ( )
70
- }
71
- }
72
-
73
- const checkSituation = ( ) => {
74
- const taskId = setInterval ( ( ) => {
75
- const needCoutinue = hasCourseNeedCountinue ( )
76
- if ( ! needCoutinue ) {
77
- clearInterval ( taskId )
78
- notifyFinish ( )
79
- } else {
80
- changeVideoIfNecessary ( )
81
- }
82
- const node = currentNode ( )
83
- const courseName = node . getElementsByClassName ( 'text-overflow' ) [ 0 ] . innerText
84
- window . document . title = `🔵正在播放【${ courseName } 】`
85
- } , 1000 )
86
- }
87
-
88
- const hasCourseNeedCountinue = ( ) => {
89
- const lists = Array . from ( document . getElementsByClassName ( 'chapter-list-box' ) )
90
- const needCoutinue = lists . some ( item => {
91
- const innerDom = item . lastElementChild . lastElementChild
92
- const type = innerDom . firstElementChild . innerHTML
93
- const status = innerDom . lastElementChild . lastElementChild . innerHTML
94
- return ( type === '视频' || type === '文档' ) && status !== '重新学习'
95
- } )
96
- return needCoutinue
97
- }
98
-
99
115
const notifyFinish = ( ) => {
100
116
chrome . runtime . sendMessage ( { event : 'finishStudyCourse' } )
101
117
}
@@ -113,13 +129,26 @@ export const createCourse = () => {
113
129
if ( domCollection && domCollection . length > 0 ) {
114
130
clearInterval ( taskId )
115
131
const lists = Array . from ( domCollection )
116
- const hasCourse = lists . some ( item => {
117
- const innerDom = item . lastElementChild . lastElementChild
132
+ let hasCourse = lists . some ( item => {
133
+ // const innerDom = item.lastElementChild.lastElementChild
134
+ const innerDom = item . lastElementChild . children [ 1 ]
118
135
const type = innerDom . firstElementChild . innerHTML
119
136
return type === '视频' || type === '文档'
120
137
} )
121
- const course = hasCourse ? new CommonCourse ( ) : new OtherCourse ( )
122
- resolve ( course )
138
+ if ( hasCourse ) {
139
+ resolve ( new CommonCourse ( ) )
140
+ return
141
+ }
142
+ // hasCourse = lists.some(item => {
143
+ // const innerDom = item.lastElementChild.children[1]
144
+ // const type = innerDom.firstElementChild.innerHTML
145
+ // return type === '视频'|| type === '文档'
146
+ // })
147
+ // if (hasCourse) {
148
+ // resolve(new RenbaoCourse())
149
+ // return
150
+ // }
151
+ resolve ( new OtherCourse ( ) )
123
152
}
124
153
} , 1000 ) ;
125
154
} )
0 commit comments