forked from moonwizardd/gbpx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
181 lines (143 loc) · 5.99 KB
/
main.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// ==UserScript==
// @name GD干部学习[不弹窗]
// @namespace http://tampermonkey.net/
// @version 1.5
// @description try to take over the world!
// @author 404
// @updateURL https://raw.githubusercontent.com/2xx8/gbpx/main/main.js
// @match https://gbpx.gd.gov.cn/*
// @match https://*.shawcoder.xyz/*
// @grant unsafeWindow
// @grant GM_openInTab
// @run-at document-start
// ==/UserScript==
const AUTO_REFRESH_TIME = 300;
var new_window;
'use strict';
//取消alert弹窗
//测试无效。学习页面的alert弹窗为页面自带,无法通过脚本跳过
unsafeWindow.alert = function(){return false};
window.alert = function(){return false};
Window.prototype.alert = function(){return false};
//列表页一级页面
if(window.location.pathname == '/gdceportal/Study/StudyCenter.aspx'){
let selector_imgAndMessage = "#aspnetForm > div:nth-child(13) > div.imgAndMessage"
wait_element(selector_imgAndMessage,function(){
document.querySelector(selector_imgAndMessage).remove()
})
let selector_header = "#aspnetForm > div.signup_header2"
wait_element(selector_header,function(){
document.querySelector(selector_header).remove()
})
}
//课程列表页面
if(window.location.pathname == '/gdceportal/Study/LearningCourse.aspx'){
//console.log('检测到课程列表页面...')
var selector_course = '#gvList_ctl02_HyperLink2' //第一个课程的标题
wait_element(selector_course,function(){
setTimeout(do_study(selector_course),3000)
})
//处理主页面等待刷新时间
wait_element("#gvList > tbody > tr:nth-child(2)",function(){
let course_percent = parseFloat(document.querySelector("#gvList > tbody > tr:nth-child(2) > td:nth-child(5) > div > div:nth-child(2)").textContent)*0.01
let study_time_hour = parseFloat(document.querySelector("#gvList > tbody > tr:nth-child(2) > td:nth-child(2)").textContent)
//一个学时对应大概42-45min
let study_time_second = parseInt(study_time_hour/60*45*60*60*(1-course_percent))+1
let refresh_time_second = AUTO_REFRESH_TIME
console.log('当前课程剩余:'+study_time_second+'s 当前进度:'+course_percent*100+'%')
//页面显示刷新倒计时
let last_time = refresh_time_second
setInterval(function(){
document.querySelector("#gvList_ctl02_HyperLink1").innerText = '🚩 '+last_time+'s';
last_time += -1;
},1000);
sleep(refresh_time_second*1000).then(() => {
new_window.close();
//console.log('移除iframe')
//document.querySelector('iframe#auto_gbpx').remove()
/*
if(is_almost_done = true){
selector_course = "#gvList_ctl03_HyperLink2";
wait_element(selector_course,function(){
setTimeout(do_study(selector_course),3000)
})
};
*/
location.reload(true);
})
})
}
//打开后课程页面
if(window.location.pathname == '/gdceportal/Study/CourseDetail.aspx'){
//console.log('准备播放视频...')
var selector_start_button = '#btnStudy'
wait_element(selector_start_button,function(){
document.querySelector(selector_start_button).click()
})
}
//视频播放页面
if(window.location.host == 'wcs1.shawcoder.xyz' & window.location.pathname == '/gdcecw/play_pc/playmp4_pc.html'){
window.onload=function(){
console.log('自动播放视频')
let is_muted = false;
const k = 20;
let j = 0;
while (!is_muted && j < k) {
sleep(200)
j = j + 1
//console.log(j)
if (document.querySelector('video')) {
document.querySelector('video').muted = true;
is_muted = true;
}
};
wait_element("#my-video > button",function () {
setTimeout(function(){
document.querySelector("#my-video_html5_api").play()
},3000)
})
}
}
function do_study(selector){
let course_link = document.querySelector(selector)
//第一个课程变色
document.querySelector("#gvList > tbody > tr:nth-child(2)").style.backgroundColor = "yellow"
document.querySelector("#gvList > tbody > tr:nth-child(2)").style.color = "red"
//document.querySelector("#gvList_ctl02_HyperLink1").innerText = '**学习中**'
//拼接课程视频页面url
let course_url = 'https://gbpx.gd.gov.cn/gdceportal/Study/'+ course_link.href.slice(14,67)
//console.log('已打开页面-> '+course_url)
//拼接跳转后的地址
//let cid = course_link.href.slice(14+21,67)
//let course_url = 'https://wcs1.shawcoder.xyz/gdcecw/play_pc/playverif_pc.html?t=2f4fd72bdf4a421f8e83d72060c414f5&courseLabel=wlxy&courseId='+cid
/*
//方式1:嵌入iframe
var body = document.getElementsByTagName("body");
var div = document.createElement("div");
div.innerHTML = '<iframe id="auto_gbpx" name="auto_gbpx" src="'+course_url+'" height = "0" width = "0" frameborder="0" scrolling="auto" style = "display:none;visibility:hidden" ></iframe>';
document.body.appendChild(div);
*/
//方式2:GM自带方法打开新页面,不被浏览器alert阻塞,可通过close关闭页面
new_window = GM_openInTab(course_url,'insert')
}
function sleep (time_ms) {
return new Promise((resolve) => setTimeout(resolve, time_ms));
}
/*
功能:等待dom加载后执行函数
dom_selector :选择器参数 待加载的dom = document.querySelector(dom_selector)
func:待执行函数体,用匿名函数传参
*/
function wait_element(dom_selector, func) {
let is_DomExist = false;
let interval = 100;//时间间隔
var int_checkDom = setInterval(() => {
if (document.querySelector(dom_selector)) {
is_DomExist = true;
func();
};
if (is_DomExist) {
clearInterval(int_checkDom);
}
}, interval);
};