Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.

Commit 2c9a435

Browse files
committed
修复超星任务跳转问题
1 parent 11db75f commit 2c9a435

7 files changed

Lines changed: 101 additions & 98 deletions

File tree

src/mooc/chaoxing/course.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,32 @@ export class CxCourse implements Mooc {
2222
}, true);
2323
}
2424

25-
public OperateCard(iframe: HTMLIFrameElement) {
25+
public async OperateCard(iframe: HTMLIFrameElement) {
2626
let iframeWindow: any = iframe.contentWindow;
2727
this.attachments = <Array<any>>iframeWindow.mArg.attachments;
2828
this.taskList = new Array();
29-
let loadOverNum = 0;
30-
this.attachments.forEach((value: any, index: number) => {
29+
for (let index = 0; index < this.attachments.length; index++) {
30+
let value = this.attachments[index];
3131
if (value.jobid == undefined) {
32-
return;
32+
continue
3333
}
3434
let task: Task;
3535
task = TaskFactory.CreateCourseTask(iframeWindow, value);
3636
if (!task) {
37-
return;
37+
continue;
3838
}
3939
task.jobIndex = index;
4040
this.taskList.push(task);
4141
let taskIndex = this.taskList.length - 1;
4242
task.Load(() => {
43-
if (++loadOverNum == this.taskList.length) {
44-
this.startTask(0, null);
45-
}
4643
});
4744
task.Complete(async () => {
4845
this.startTask(taskIndex + 1, task);
4946
});
50-
task.Init();
51-
});
52-
Application.App.log.Debug("任务点参数", this.attachments);
53-
if (this.taskList.length == 0) {
54-
//无任务点
55-
this.startTask(0, null);
47+
await task.Init();
5648
}
49+
Application.App.log.Debug("任务点参数", this.attachments);
50+
this.startTask(0, null);
5751
}
5852

5953
protected async startTask(index: number, nowtask: Task) {
@@ -82,7 +76,7 @@ export class CxCourse implements Mooc {
8276
let interval = Application.App.config.interval;
8377
Application.App.log.Info(interval + "分钟后自动切换下一个任务点");
8478
this.timer = setTimeout(() => {
85-
func();
79+
Application.App.config.auto && func();
8680
}, interval * 60000);
8781
}
8882

src/mooc/chaoxing/task.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export abstract class Task {
1818
this.completeCallback = callback;
1919
}
2020

21-
public Init(): void {
21+
public Init(): Promise<any> {
22+
return new Promise(resolve => {
23+
resolve();
24+
});
2225
}
2326

2427
public Load(callback: () => void): void {

src/mooc/chaoxing/topic.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,13 @@ import {CssBtn} from "./utils";
22
import {createBtn} from "@App/internal/utils/utils";
33
import {Application} from "@App/internal/application";
44
import {
5-
ToolsQuestionBankFacade,
65
SwitchTopicType,
76
Question,
8-
QuestionBankFacade, TopicStatus, QuestionStatus
7+
QuestionBankFacade, QuestionStatus
98
} from "@App/internal/app/question";
109
import {CxQuestionFactory} from "./question";
1110
import {Topic, QueryQuestions} from "@App/internal/app/topic";
12-
// import {TaskFactory} from "@App/mooc/chaoxing/factory";
1311
import {CxTaskControlBar, Task} from "@App/mooc/chaoxing/task";
14-
import any = jasmine.any;
15-
//
16-
// export class HomeworkTopicFactory implements TaskFactory {
17-
// protected task: TopicAdapter;
18-
//
19-
// protected createQuestion(el: HTMLElement): Question {
20-
// return CxQuestionFactory.CreateHomeWorkQuestion(el);
21-
// }
22-
//
23-
// public CreateTask(context: any, taskinfo: any): Task {
24-
// let topic = new HomeworkTopic(context, new ToolsQuestionBankFacade("cx", taskinfo));
25-
// topic.SetQueryQuestions(new CourseQueryQuestion(context, this.createQuestion));
26-
// this.task = new TopicAdapter(context, taskinfo, topic);
27-
//
28-
// let btn = CssBtn(createBtn("搜索答案", "搜索题目答案"));
29-
// if ((<HTMLInputElement>document.querySelector("input#workRelationId"))) {
30-
// document.querySelector(".CyTop").append(btn);
31-
// btn.onclick = async () => {
32-
// btn.innerText = "答案搜索中...";
33-
// this.task.Start().then((ret: any) => {
34-
// ret = ret || "搜索题目";
35-
// btn.innerText = ret;
36-
// });
37-
// };
38-
// }
39-
// return this.task;
40-
// }
41-
// }
42-
4312

4413
export class CxTopicControlBar extends CxTaskControlBar {
4514
public defaultBtn() {
@@ -74,6 +43,7 @@ export class TopicAdapter extends Task {
7443
Application.App.log.Debug("题目信息", this.taskinfo);
7544
this.topic.Init();
7645
this.loadCallback && this.loadCallback();
46+
resolve();
7747
});
7848
}
7949

src/mooc/chaoxing/video.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,32 +149,36 @@ export class Video extends Task {
149149
protected afterPoint: number = 0;
150150
protected flash: boolean;
151151

152-
public Init() {
153-
Application.App.log.Debug("播放器配置", this.taskinfo);
154-
let timer = this.context.setInterval(() => {
155-
try {
156-
let video = this.context.document.getElementById("video_html5_api");
157-
if (video == undefined) {
158-
if (this.context.document.querySelector("#reader").innerHTML.indexOf("您没有安装flashplayer") >= 0) {
159-
this.context.clearInterval(timer);
160-
this.flash = true;
161-
this.loadCallback && this.loadCallback();
152+
public Init(): Promise<any> {
153+
return new Promise(resolve => {
154+
Application.App.log.Debug("播放器配置", this.taskinfo);
155+
let timer = this.context.setInterval(() => {
156+
try {
157+
let video = this.context.document.getElementById("video_html5_api");
158+
if (video == undefined) {
159+
if (this.context.document.querySelector("#reader").innerHTML.indexOf("您没有安装flashplayer") >= 0) {
160+
this.context.clearInterval(timer);
161+
this.flash = true;
162+
this.loadCallback && this.loadCallback();
163+
resolve();
164+
}
165+
return;
162166
}
163-
return;
167+
this.context.clearInterval(timer);
168+
this.video = video;
169+
this.initPlayer();
170+
this.video.addEventListener("ended", () => {
171+
this.completeCallback && this.completeCallback();
172+
});
173+
this.video.addEventListener("pause", () => {
174+
Application.App.config.auto && this.video.play();
175+
});
176+
this.loadCallback && this.loadCallback();
177+
resolve();
178+
} catch (error) {
164179
}
165-
this.context.clearInterval(timer);
166-
this.video = video;
167-
this.initPlayer();
168-
this.video.addEventListener("ended", () => {
169-
this.completeCallback && this.completeCallback();
170-
});
171-
this.video.addEventListener("pause", () => {
172-
Application.App.config.auto && this.video.play();
173-
});
174-
this.loadCallback && this.loadCallback();
175-
} catch (error) {
176-
}
177-
}, 500);
180+
}, 500);
181+
});
178182
}
179183

180184
public Start(): void {

src/mooc/course163/course163.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import { Mooc } from "../factory";
2-
import { Hook, Context } from "@App/internal/utils/hook";
3-
import { createBtn, substrex, protocolPrompt } from "@App/internal/utils/utils";
1+
import {Mooc} from "../factory";
2+
import {Hook, Context} from "@App/internal/utils/hook";
3+
import {createBtn, substrex, protocolPrompt} from "@App/internal/utils/utils";
44
import "../../views/common";
5-
import { CourseTopic, CourseQueryAnswer } from "./question";
6-
import { ToolsQuestionBankFacade, ToolsQuestionBank, QuestionBank, QuestionBankFacade, Answer, Option, PushAnswer } from "@App/internal/app/question";
7-
import { Application } from "@App/internal/application";
5+
import {CourseTopic, CourseQueryAnswer} from "./question";
6+
import {
7+
ToolsQuestionBankFacade,
8+
ToolsQuestionBank,
9+
QuestionBank,
10+
QuestionBankFacade,
11+
Answer,
12+
Option,
13+
PushAnswer,
14+
QuestionStatusString
15+
} from "@App/internal/app/question";
16+
import {Application} from "@App/internal/application";
817

918
export class Course163 implements Mooc {
1019

@@ -22,12 +31,16 @@ export class Course163 implements Mooc {
2231
get: function () {
2332
if (this.response.indexOf("paper:s0") > 0) {
2433
self.collectAnswer(this.response);
25-
setTimeout(() => { self.courseTopic() }, 1000);
34+
setTimeout(() => {
35+
self.courseTopic()
36+
}, 1000);
2637
} else if (this.response.indexOf("tname:\"") > 0) {
2738
if (this.response.indexOf("answers:s0") > 0) {
2839
self.collectAnswer(this.response);
2940
}
30-
setTimeout(() => { self.examTopic() }, 1000);
41+
setTimeout(() => {
42+
self.examTopic()
43+
}, 1000);
3144
}
3245
return this.response;
3346
}
@@ -53,8 +66,8 @@ export class Course163 implements Mooc {
5366
protocolPrompt("你正准备使用中国慕课的答题功能,相应的我们需要你的正确答案,同意之后插件将自动检索你的所有答案\n* 本项选择不会影响你的正常使用(协议当前版本有效)\n* 手动点击答题结果页面自动采集页面答案\n", "course_answer_collect", "我同意");
5467

5568
search.innerText = "搜索中...";
56-
search.innerText = await topic.QueryAnswer();
57-
search.innerText = "搜索答案";
69+
let ret = await topic.QueryAnswer();
70+
search.innerText = QuestionStatusString(ret);
5871
}
5972
divel.insertBefore(search, divel.firstChild);
6073
}
@@ -94,7 +107,7 @@ export class Course163 implements Mooc {
94107
tmpAnswer.topic = topic.title;
95108
tmpAnswer.type = 4;
96109
tmpAnswer.correct = new Array<Option>();
97-
if(!topic.stdAnswer){
110+
if (!topic.stdAnswer) {
98111
continue;
99112
}
100113
tmpAnswer.correct.push({
@@ -106,13 +119,14 @@ export class Course163 implements Mooc {
106119
tmpAnswer.topic = topic.title;
107120
tmpAnswer.type = 3;
108121
tmpAnswer.correct = new Array<Option>();
109-
if(!topic.optionDtos){
122+
if (!topic.optionDtos) {
110123
continue;
111124
}
112125
for (let n = 0; n < topic.optionDtos.length; n++) {
113126
if (topic.optionDtos[n].answer) {
114127
tmpAnswer.correct.push({
115-
option: "正确" == topic.optionDtos[n].content, content: "正确" == topic.optionDtos[n].content,
128+
option: "正确" == topic.optionDtos[n].content,
129+
content: "正确" == topic.optionDtos[n].content,
116130
});
117131
break;
118132
}
@@ -121,7 +135,7 @@ export class Course163 implements Mooc {
121135
}
122136
continue;
123137
}
124-
if(!topic.optionDtos){
138+
if (!topic.optionDtos) {
125139
continue;
126140
}
127141
let option = new Array<Option>();
@@ -130,7 +144,7 @@ export class Course163 implements Mooc {
130144
tmpAnswer.topic = topic.title;
131145
tmpAnswer.type = topic.type;
132146
for (let i = 0; i < topic.optionDtos.length; i++) {
133-
let opt = { content: topic.optionDtos[i].content, option: String.fromCharCode(65 + i) };
147+
let opt = {content: topic.optionDtos[i].content, option: String.fromCharCode(65 + i)};
134148
if (topic.optionDtos[i].answer) {
135149
correct.push(opt);
136150
}

src/mooc/zhihuishu/exam.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
import { Mooc } from "../factory";
2-
import { createBtn, substrex, randNumber, protocolPrompt } from "@App/internal/utils/utils";
1+
import {Mooc} from "../factory";
2+
import {createBtn, substrex, randNumber, protocolPrompt} from "@App/internal/utils/utils";
33
import "../../views/common";
4-
import { Topic, QueryQuestions } from "@App/internal/app/topic";
5-
import { Question, ToolsQuestionBankFacade, ToolsQuestionBank, TopicType, SwitchTopicType, TopicStatus, Answer, TopicStatusString, PushAnswer } from "@App/internal/app/question";
6-
import { CreateNoteLine } from "../chaoxing/utils";
4+
import {Topic, QueryQuestions} from "@App/internal/app/topic";
5+
import {
6+
Question,
7+
ToolsQuestionBankFacade,
8+
ToolsQuestionBank,
9+
TopicType,
10+
SwitchTopicType,
11+
TopicStatus,
12+
Answer,
13+
TopicStatusString,
14+
PushAnswer,
15+
QuestionStatusString
16+
} from "@App/internal/app/question";
17+
import {CreateNoteLine} from "../chaoxing/utils";
718

819
//TODO: 与超星一起整合优化
920
export class ZhsExam implements Mooc {
@@ -18,10 +29,14 @@ export class ZhsExam implements Mooc {
1829
this.topic.SetQueryQuestions(new ExamQueryQuestion());
1930
window.addEventListener("load", () => {
2031
setTimeout(() => {
21-
document.oncontextmenu = () => { }
22-
document.oncopy = () => { }
23-
document.onpaste = () => { }
24-
document.onselectstart = () => { }
32+
document.oncontextmenu = () => {
33+
}
34+
document.oncopy = () => {
35+
}
36+
document.onpaste = () => {
37+
}
38+
document.onselectstart = () => {
39+
}
2540
if (document.querySelectorAll(".examInfo.infoList.clearfix").length <= 0) {
2641
this.createBtn();
2742
} else {
@@ -41,7 +56,7 @@ export class ZhsExam implements Mooc {
4156

4257
btn.innerText = "搜索中...";
4358
let ret = await self.topic.QueryAnswer();
44-
btn.innerText = ret;
59+
btn.innerText = QuestionStatusString(ret);
4560
return false;
4661
}
4762
}
@@ -64,7 +79,8 @@ class ExamQueryQuestion implements QueryQuestions {
6479

6580
protected createQuestion(type: TopicType, el: HTMLElement): Question {
6681
switch (type) {
67-
case 1: case 2: {
82+
case 1:
83+
case 2: {
6884
return new ZhsSelectQuestion(el, type);
6985
}
7086
case 3: {
@@ -81,6 +97,7 @@ class ExamQueryQuestion implements QueryQuestions {
8197
abstract class ZhsQuestion implements Question {
8298
protected el: HTMLElement;
8399
protected type: TopicType;
100+
84101
constructor(el: HTMLElement, type: TopicType) {
85102
this.el = el;
86103
this.type = type;

src/tampermonkey/cxmooc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// @match *://*/work/selectWorkQuestionYiPiYue?*
1515
// @match *://*/work/doHomeWorkNew?*
1616
// @match *://*/ananas/modules/video/index.html?*
17+
// @match *://*.chaoxing.com/exam/test?*
1718
// @grant GM_xmlhttpRequest
1819
// @grant unsafeWindow
1920
// @license MIT

0 commit comments

Comments
 (0)