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

Commit afe12b0

Browse files
committed
修复超星填空题
1 parent 706813d commit afe12b0

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

src/mooc/chaoxing/factory.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class TaskFactory {
5555
let topic = new CxCourseTopic(contentWindow, new ToolsQuestionBankFacade("cx", {
5656
refer: (<Window>context).document.URL, id: taskinfo.property.workid, info: taskinfo.property.workid,
5757
}));
58-
topic.SetQueryQuestions(new CxCourseQueryQuestion(contentWindow, (el: HTMLElement): Question => {
59-
return CxQuestionFactory.CreateCourseQuestion(el);
58+
topic.SetQueryQuestions(new CxCourseQueryQuestion(contentWindow, (context: any, el: HTMLElement): Question => {
59+
return CxQuestionFactory.CreateCourseQuestion(context, el);
6060
}));
6161
let bar = new CxTopicControlBar(prev, new TopicAdapter(context, taskinfo, topic));
6262
if (Application.App.config.answer_ignore) {
@@ -105,8 +105,8 @@ export class TaskFactory {
105105
return false;
106106
};
107107
} else {
108-
topic.SetQueryQuestions(new CxCourseQueryQuestion(context, (el: HTMLElement): Question => {
109-
return CxQuestionFactory.CreateExamCollectQuestion(el);
108+
topic.SetQueryQuestions(new CxCourseQueryQuestion(context, (context: any, el: HTMLElement): Question => {
109+
return CxQuestionFactory.CreateExamCollectQuestion(context, el);
110110
}));
111111
}
112112
return task;
@@ -118,8 +118,8 @@ export class TaskFactory {
118118
bank.CheckCourse();
119119
}
120120
let topic = new HomeworkTopic(context, bank);
121-
topic.SetQueryQuestions(new CxCourseQueryQuestion(context, (el: HTMLElement): Question => {
122-
return CxQuestionFactory.CreateHomeWorkQuestion(el);
121+
topic.SetQueryQuestions(new CxCourseQueryQuestion(context, (context: any, el: HTMLElement): Question => {
122+
return CxQuestionFactory.CreateHomeWorkQuestion(context, el);
123123
}));
124124
let task = new TopicAdapter(context, taskinfo, topic);
125125
let btn = CssBtn(createBtn("搜索答案", "搜索题目答案"));

src/mooc/chaoxing/question.ts

+23-21
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ import {CreateNoteLine} from "./utils";
1313

1414
//TODO: 优化
1515
export class CxQuestionFactory {
16-
public static CreateCourseQuestion(el: HTMLElement): Question {
16+
public static CreateCourseQuestion(context: any, el: HTMLElement): Question {
1717
let ret = SwitchTopicType(substrex(el.innerText, '【', '】'));
18-
return this.CreateCourseQuestionByTopicType(ret, el);
18+
return this.CreateCourseQuestionByTopicType(context, ret, el);
1919
}
2020

21-
public static CreateExamQuestion(type: TopicType, el: HTMLElement): Question {
21+
public static CreateExamQuestion(context: any, type: TopicType, el: HTMLElement): Question {
2222
let processor = new ExamQuestionProcessor();
2323
let ret: Question = null;
2424
this.RemoveNotice(el);
2525
switch (type) {
2626
case 1:
2727
case 2: {
28-
ret = new cxExamSelectQuestion(el, type, processor);
28+
ret = new cxExamSelectQuestion(context, el, type, processor);
2929
break;
3030
}
3131
case 3: {
32-
ret = new cxExamJudgeQuestion(el, type, processor);
32+
ret = new cxExamJudgeQuestion(context, el, type, processor);
3333
break;
3434
}
3535
case 4: {
36-
ret = new cxExamFillQuestion(el, type, processor);
36+
ret = new cxExamFillQuestion(context, el, type, processor);
3737
break;
3838
}
3939
default: {
@@ -44,22 +44,22 @@ export class CxQuestionFactory {
4444
return ret;
4545
}
4646

47-
public static CreateCourseQuestionByTopicType(type: TopicType, el: HTMLElement): Question {
47+
public static CreateCourseQuestionByTopicType(context: any, type: TopicType, el: HTMLElement): Question {
4848
let ret: Question = null;
4949
let processor = new CourseQuestionProcessor();
5050
this.RemoveNotice(el);
5151
switch (type) {
5252
case 1:
5353
case 2: {
54-
ret = new cxSelectQuestion(el, type, processor);
54+
ret = new cxSelectQuestion(context, el, type, processor);
5555
break;
5656
}
5757
case 3: {
58-
ret = new cxJudgeQuestion(el, type, processor);
58+
ret = new cxJudgeQuestion(context, el, type, processor);
5959
break;
6060
}
6161
case 4: {
62-
ret = new cxFillQuestion(el, type, processor);
62+
ret = new cxFillQuestion(context, el, type, processor);
6363
break;
6464
}
6565
default: {
@@ -81,34 +81,34 @@ export class CxQuestionFactory {
8181
return null;
8282
}
8383

84-
public static CreateHomeWorkQuestion(el: HTMLElement): Question {
84+
public static CreateHomeWorkQuestion(context: any, el: HTMLElement): Question {
8585
let ret = CxQuestionFactory.getBeforeType(el);
86-
return this.CreateCourseQuestionByTopicType(SwitchTopicType(substrex(ret.innerText, ".", "(")), el);
86+
return this.CreateCourseQuestionByTopicType(context, SwitchTopicType(substrex(ret.innerText, ".", "(")), el);
8787
}
8888

8989
//TODO:写的什么玩意啊
90-
public static CreateExamCollectQuestion(el: HTMLElement): Question {
90+
public static CreateExamCollectQuestion(context: any, el: HTMLElement): Question {
9191
let ret = CxQuestionFactory.getBeforeType(el.parentElement);
9292
let txt = ret.innerText.match(/(.*?)[\s|]/)[1];
93-
return this.CreateExamQuestionByTopicType(SwitchTopicType(txt), el);
93+
return this.CreateExamQuestionByTopicType(context, SwitchTopicType(txt), el);
9494
}
9595

96-
public static CreateExamQuestionByTopicType(type: TopicType, el: HTMLElement): Question {
96+
public static CreateExamQuestionByTopicType(context: any, type: TopicType, el: HTMLElement): Question {
9797
let ret: Question = null;
9898
let processor = new CourseQuestionProcessor();
9999
this.RemoveNotice(el);
100100
switch (type) {
101101
case 1:
102102
case 2: {
103-
ret = new cxSelectQuestion(el, type, processor);
103+
ret = new cxSelectQuestion(context, el, type, processor);
104104
break;
105105
}
106106
case 3: {
107-
ret = new cxJudgeQuestion(el, type, processor);
107+
ret = new cxJudgeQuestion(context, el, type, processor);
108108
break;
109109
}
110110
case 4: {
111-
ret = new cxExamFillQuestion(el, type, processor);
111+
ret = new cxExamFillQuestion(context, el, type, processor);
112112
break;
113113
}
114114
default: {
@@ -168,8 +168,10 @@ abstract class cxQuestion implements Question {
168168
protected el: HTMLElement;
169169
protected type: TopicType;
170170
protected processor: QuestionProcessor;
171+
protected context: Window;
171172

172-
constructor(el: HTMLElement, type: TopicType, processor: QuestionProcessor) {
173+
constructor(context: Window, el: HTMLElement, type: TopicType, processor: QuestionProcessor) {
174+
this.context = context;
173175
this.el = el;
174176
this.type = type;
175177
this.processor = processor;
@@ -400,12 +402,12 @@ class cxFillQuestion extends cxQuestion implements Question {
400402
flag++;
401403
let el = <HTMLInputElement>options[j].querySelector("input.inp");
402404
if (!el) {
403-
let uedit = (<any>window).$(options[j]).find('textarea');
405+
let uedit = (<any>this.context).$(options[j]).find('textarea');
404406
if (uedit.length <= 0) {
405407
this.AddNotice(this.getOption(options[j]) + "空发生了一个错误");
406408
continue;
407409
}
408-
(<any>window).UE.getEditor(uedit.attr('name')).setContent(answer.correct[i].content);
410+
(<any>this.context).UE.getEditor(uedit.attr('name')).setContent(answer.correct[i].content);
409411
this.AddNotice(this.getOption(options[j]) + ":" + answer.correct[i].content);
410412
} else {
411413
el.value = removeHTMLTag(answer.correct[i].content);

src/mooc/chaoxing/topic.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export class TopicAdapter extends CxTask {
7777

7878
export class CxCourseQueryQuestion implements QueryQuestions {
7979
protected context: any;
80-
protected createQuestion: (el: HTMLElement) => Question;
80+
protected createQuestion: (context: any, el: HTMLElement) => Question;
8181

82-
constructor(content: any, createQuestion: (el: HTMLElement) => Question) {
82+
constructor(content: any, createQuestion: (context: any, el: HTMLElement) => Question) {
8383
this.context = content;
8484
this.createQuestion = createQuestion;
8585
}
@@ -88,7 +88,7 @@ export class CxCourseQueryQuestion implements QueryQuestions {
8888
let timu = <Array<HTMLElement>>this.context.document.querySelectorAll(".TiMu");
8989
let ret = new Array<Question>();
9090
timu.forEach((val) => {
91-
let question = this.createQuestion(val);
91+
let question = this.createQuestion(this.context, val);
9292
if (question == null) {
9393
return;
9494
}
@@ -170,7 +170,7 @@ export class ExamTopic extends Topic implements QueryQuestions {
170170
public QueryQuestions(): Question[] {
171171
let current = document.querySelector(".current");
172172
let topicType = SwitchTopicType((<HTMLElement>current.parentElement.previousElementSibling).innerText);
173-
let question = CxQuestionFactory.CreateExamQuestion(topicType, document.querySelector(".leftContent.TiMu"));
173+
let question = CxQuestionFactory.CreateExamQuestion(window, topicType, document.querySelector(".leftContent.TiMu"));
174174
let ret = new Array();
175175
if (question == null) {
176176
return ret;

tests/utils.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe("remove html", () => {
66
let eg = "这是一句正常的话,应该不要发送改变";
77
expect(removeHTML(eg)).toEqual(eg);
88
expect(removeHTML("包含一些中文符号,例如:()?这样一些“”")).toEqual("包含一些中文符号,例如:()?这样一些\"\"");
9+
expect(removeHTML('123 124 <br> <br>')).toEqual("123 124")
910
});
1011
it("包含html", () => {
1112
expect(removeHTML('<span style=";font-family:宋体;font-size:16px"><span style="font-family:宋体">依靠群众求胜利</span></span>')).toEqual("依靠群众求胜利");

0 commit comments

Comments
 (0)