-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
强国学习.js
369 lines (351 loc) · 13.3 KB
/
强国学习.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// ==UserScript==
// @name 强国学习
// @namespace 雪导.
// @version 2.1.1
// @description 问题反馈位置: https://github.com/TechXueXi/techxuexi-js/issues 。 强国学习自动答题,目前实现 每日答题,每周答题,专项答题(操作方法更新为:打开答题页面后,手动刷新下自动开启)
// @author 雪导、天幽
// @require https://greasyfork.org/scripts/423313-utils%E7%8E%AF%E5%A2%83/code/Utils%E7%8E%AF%E5%A2%83.js?version=911306
// @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
// @match https://www.xuexi.cn
// @match https://www.xuexi.cn/*
// @match https://pc.xuexi.cn/points/exam-practice.html*
// @match https://pc.xuexi.cn/points/exam-weekly-detail.html*
// @match https://pc.xuexi.cn/points/exam-paper-detail.html*
// @match https://pc.xuexi.cn/points/my-study.html*
// @match https://pc.xuexi.cn/points/exam-index.html*
// @match https://pc-api.xuexi.cn/open/api/score/today/queryrate
// @grant none
// ==/UserScript==
window.onload = async function () {
const $X = new Utils("学习强国");
//移除顶部
const header = document.querySelector("#app > div > div.layout-header");
if (header != null) {
header.parentNode.removeChild(header);
console.log("移除header乱七八糟的dom");
}
//移除底部
const footer = document.querySelector("#app > div > div.layout-footer");
if (footer != null) {
footer.parentNode.removeChild(footer);
console.log("移除footer乱七八糟的dom");
}
// 创建问题反馈
const startQuestionBtn = () => {
var div = document.createElement("div");
div.innerHTML = "<span>问题反馈</span>";
//为div创建属性class = "test"
var divattr = document.createAttribute("class");
divattr.value = "question-btn";
//把属性class = "test"添加到div
div.setAttributeNode(divattr);
//为div添加样式
var style = document.createAttribute("style");
div.setAttributeNode(style);
div.style.backgroundColor = "green";
div.style.color = "#fff";
div.style.textAlign = "center";
div.style.width = "80px";
div.style.borderColor = "#000";
div.style.marginLeft = "0%";
div.style.marginTop = "1%";
document.querySelector(".ant-breadcrumb").appendChild(div);
$(".question-btn").click(() => {
window.open("https://gitee.com/qq34347476/tampermonkey/issues");
});
};
// 创建每日答题
const startDayBtn = () => {
var div = document.createElement("div");
div.innerHTML = "<span>每日答题</span>";
//为div创建属性class = "test"
var divattr = document.createAttribute("class");
divattr.value = "start-btn";
//把属性class = "test"添加到div
div.setAttributeNode(divattr);
//为div添加样式
var style = document.createAttribute("style");
div.setAttributeNode(style);
div.style.backgroundColor = "#F00";
div.style.color = "#fff";
div.style.textAlign = "center";
div.style.width = "80px";
div.style.borderColor = "#000";
div.style.marginLeft = "0%";
div.style.marginTop = "1%";
document.querySelector(".ant-breadcrumb").appendChild(div);
$(".start-btn").click(() => {
window.open("https://pc.xuexi.cn/points/exam-practice.html");
});
};
// 创建专项答题
const startExamBtn = () => {
var div = document.createElement("div");
div.innerHTML = "<span>专项答题</span>";
//为div创建属性class = "test"
var divattr = document.createAttribute("class");
divattr.value = "start-btn3";
//把属性class = "test"添加到div
div.setAttributeNode(divattr);
//为div添加样式
var style = document.createAttribute("style");
div.setAttributeNode(style);
div.style.backgroundColor = "#F00";
div.style.color = "#fff";
div.style.textAlign = "center";
div.style.width = "80px";
div.style.borderColor = "#000";
div.style.marginLeft = "0%";
div.style.marginTop = "1%";
document.querySelector(".ant-breadcrumb").appendChild(div);
$(".start-btn3").click(() => {
window.open("https://pc.xuexi.cn/points/exam-paper-list.html");
});
};
// 创建每周答题
const startWeekBtn = () => {
var div = document.createElement("div");
div.innerHTML = "<span>每周答题</span>";
//为div创建属性class = "test"
var divattr = document.createAttribute("class");
divattr.value = "start-btn2";
//把属性class = "test"添加到div
div.setAttributeNode(divattr);
//为div添加样式
var style = document.createAttribute("style");
div.setAttributeNode(style);
div.style.backgroundColor = "#F00";
div.style.color = "#fff";
div.style.textAlign = "center";
div.style.width = "80px";
div.style.borderColor = "#000";
div.style.marginLeft = "0%";
div.style.marginTop = "1%";
document.querySelector(".ant-breadcrumb").appendChild(div);
$(".start-btn2").click(() => {
window.open("https://pc.xuexi.cn/points/exam-weekly-list.html");
});
};
const getBtnDom = async () => {
return new Promise((resolve) => {
setTimeout(() => {
let nextAll = document.querySelectorAll(".ant-btn");
let next = nextAll[0];
if (nextAll.length == 2) {
//俩按钮,说明有个按钮是交卷。
next = nextAll[1];
}
console.log("btn按钮状态", next);
resolve(next);
}, 2000);
});
};
const doit = async () => {
console.log("===========开始答题===========");
console.log("延时500ms");
await $X.wait(500);
const next = await getBtnDom();
console.log("next", next);
if (next.disabled) {
document.querySelector(".tips").click();
console.log("延时500ms");
await $X.wait(500);
if (
document.querySelector(".ant-popover-inner-content").textContent ===
"请观看视频"
) {
console.log("需要观看视频");
alert("请手动作答");
// window.location.reload()
return;
}
//所有提示
let allTips = document.querySelectorAll("font[color=red]");
//单选多选时候的按钮
let buttons = document.querySelectorAll(".q-answer");
//填空时候的那个textbox,这里假设只有一个填空
let textboxs = document.querySelectorAll("input");
//问题类型
let qType = document.querySelector(".q-header").textContent;
console.log("问题类型qType", qType);
qType = qType.substr(0, 3);
switch (qType) {
case "填空题":
//第几个填空
let mevent = new Event("input", { bubbles: true });
if (textboxs.length > 1) {
//若不止是一个空
//填空数量和提示数量是否一致
if (allTips.length == textboxs.length) {
for (
let i = 0;
i < allTips.length;
i++ //数量一致,则一一对应。
) {
let tip = allTips[i];
let tipText = tip.textContent;
if (tipText.length > 0) {
//通过设置属性,然后立即让他冒泡这个input事件.
//否则1,setattr后,内容消失.
//否则2,element.value=124后,属性值value不会改变,所以冒泡也不管用.
textboxs[i].setAttribute("value", tipText);
textboxs[i].dispatchEvent(mevent);
}
}
} else {
//若填空数量和提示数量不一致,那么,应该都是提示数量多。
if (allTips.length > textboxs.length) {
let lineFeed = document.querySelector(".line-feed").textContent; //这个是提示的所有内容,不仅包含红色答案部分。
let n = 0; //计数,第几个tip。
for (
let j = 0;
j < textboxs.length;
j++ //多个填空
) {
let tipText = allTips[n].textContent;
let nextTipText = "";
do {
tipText += nextTipText;
if (n < textboxs.length - 1) {
n++;
nextTipText = allTips[n].textContent;
} else {
nextTipText = "结束了,没有了。";
}
} while (lineFeed.indexOf(tipText + nextTipText));
textboxs[j].setAttribute("value", tipText);
textboxs[j].dispatchEvent(mevent);
}
} else {
//提示数量少于填空数量,则我无法分析, 回头研究,暂时放弃作答,刷新题库浏览器
// location.reload()
}
return doit();
}
} else if (textboxs.length == 1) {
//只有一个空,直接把所有tips合并。
let tipText = "";
for (let i = 0; i < allTips.length; i++) {
tipText += allTips[i].textContent;
}
textboxs[0].setAttribute("value", tipText);
textboxs[0].dispatchEvent(mevent);
await $X.wait(500);
// return doit()
} else {
//怕有没空白的情况。 看视频。。
console.log("填空题,看视频?");
window.location.href = "http://www.baidu.com";
}
return doit();
case "多选题":
//循环选项列表。用来点击
for (let js = 0; js < buttons.length; js++) {
let cButton = buttons[js];
for (
let i = 0;
i < allTips.length;
i++ //循环提示列表。
) {
let tip = allTips[i];
let tipText = tip.textContent;
if (tipText.length > 0) {
//提示内容长度大于0
let cButtonText = cButton.textContent; //选项按钮的内容
console.log("cButtonText", cButtonText);
console.log("tipText", tipText);
//循环对比点击
if (
cButtonText.indexOf(tipText) > -1 ||
tipText.indexOf(cButtonText) > -1
) {
cButton.click();
}
}
}
}
return doit();
case "单选题":
//单选,所以所有的提示,其实是同一个。有时候,对方提示会分成多个部分。
//case 块里不能直接用let。所以增加了个if。
if (true) {
//把红色提示组合为一条
let tipText = "";
for (let i = 0; i < allTips.length; i++) {
tipText += allTips[i].textContent;
}
if (tipText.length > 0) {
//循环对比后点击 答案是否包含正确答案
for (let js = 0; js < buttons.length; js++) {
let cButton = buttons[js];
let cButtonText = cButton.textContent;
//通过判断是否相互包含,来确认是不是此选项
if (
cButtonText.indexOf(tipText) > -1 ||
tipText.indexOf(cButtonText) > -1
) {
console.log("延时500选择");
await $X.wait(500);
cButton.click();
await $X.wait(500);
console.log("下一步");
return doit();
}
}
// 循环对比答案,若不纯在包含答案 则走 这套比对答案逻辑
console.log("循环比对答案 【相似度】");
let xiangsidu = []; // 相似度
let max_xiangsidu = 0;
let index = 0;
for (let js = 0; js < buttons.length; js++) {
let cButton = buttons[js];
let cButtonText = cButton.textContent;
//通过判断是否相互包含,来确认是不是此选项
xiangsidu.push($X.strSimilarity2Percent(tipText, cButtonText));
}
max_xiangsidu = $X.getMaxNumOfArr(xiangsidu);
index = xiangsidu.findIndex((item) => item === max_xiangsidu);
console.log(`几个答案相似度【$X{max_xiangsidu}】`);
console.log(`找最相似的答案【$X{index}】`);
buttons[index].click();
await $X.wait(500);
document.querySelector(".ant-btn").click();
await $X.wait(500);
return doit();
}
}
break;
default:
break;
}
} else {
// 可以点击
if (
next.textContent != "再练一次" &&
next.textContent != "再来一组" &&
next.textContent != "查看解析"
) {
next.click();
await $X.wait(500);
doit();
} else {
// 结束
console.log("答题结束");
$X.done();
}
}
};
startQuestionBtn();
startDayBtn();
startWeekBtn();
startExamBtn();
let btn = document.querySelector(".ant-btn");
if (btn) {
if (btn.textContent === "确 定" || btn.textContent === "下一题") {
await $X.wait(500);
doit();
} else {
location.reload();
}
}
};