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

Commit

Permalink
修复超星任务跳转问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Mar 26, 2020
1 parent 11db75f commit 2c9a435
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 98 deletions.
24 changes: 9 additions & 15 deletions src/mooc/chaoxing/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,32 @@ export class CxCourse implements Mooc {
}, true);
}

public OperateCard(iframe: HTMLIFrameElement) {
public async OperateCard(iframe: HTMLIFrameElement) {
let iframeWindow: any = iframe.contentWindow;
this.attachments = <Array<any>>iframeWindow.mArg.attachments;
this.taskList = new Array();
let loadOverNum = 0;
this.attachments.forEach((value: any, index: number) => {
for (let index = 0; index < this.attachments.length; index++) {
let value = this.attachments[index];
if (value.jobid == undefined) {
return;
continue
}
let task: Task;
task = TaskFactory.CreateCourseTask(iframeWindow, value);
if (!task) {
return;
continue;
}
task.jobIndex = index;
this.taskList.push(task);
let taskIndex = this.taskList.length - 1;
task.Load(() => {
if (++loadOverNum == this.taskList.length) {
this.startTask(0, null);
}
});
task.Complete(async () => {
this.startTask(taskIndex + 1, task);
});
task.Init();
});
Application.App.log.Debug("任务点参数", this.attachments);
if (this.taskList.length == 0) {
//无任务点
this.startTask(0, null);
await task.Init();
}
Application.App.log.Debug("任务点参数", this.attachments);
this.startTask(0, null);
}

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

Expand Down
5 changes: 4 additions & 1 deletion src/mooc/chaoxing/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export abstract class Task {
this.completeCallback = callback;
}

public Init(): void {
public Init(): Promise<any> {
return new Promise(resolve => {
resolve();
});
}

public Load(callback: () => void): void {
Expand Down
34 changes: 2 additions & 32 deletions src/mooc/chaoxing/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,13 @@ import {CssBtn} from "./utils";
import {createBtn} from "@App/internal/utils/utils";
import {Application} from "@App/internal/application";
import {
ToolsQuestionBankFacade,
SwitchTopicType,
Question,
QuestionBankFacade, TopicStatus, QuestionStatus
QuestionBankFacade, QuestionStatus
} from "@App/internal/app/question";
import {CxQuestionFactory} from "./question";
import {Topic, QueryQuestions} from "@App/internal/app/topic";
// import {TaskFactory} from "@App/mooc/chaoxing/factory";
import {CxTaskControlBar, Task} from "@App/mooc/chaoxing/task";
import any = jasmine.any;
//
// export class HomeworkTopicFactory implements TaskFactory {
// protected task: TopicAdapter;
//
// protected createQuestion(el: HTMLElement): Question {
// return CxQuestionFactory.CreateHomeWorkQuestion(el);
// }
//
// public CreateTask(context: any, taskinfo: any): Task {
// let topic = new HomeworkTopic(context, new ToolsQuestionBankFacade("cx", taskinfo));
// topic.SetQueryQuestions(new CourseQueryQuestion(context, this.createQuestion));
// this.task = new TopicAdapter(context, taskinfo, topic);
//
// let btn = CssBtn(createBtn("搜索答案", "搜索题目答案"));
// if ((<HTMLInputElement>document.querySelector("input#workRelationId"))) {
// document.querySelector(".CyTop").append(btn);
// btn.onclick = async () => {
// btn.innerText = "答案搜索中...";
// this.task.Start().then((ret: any) => {
// ret = ret || "搜索题目";
// btn.innerText = ret;
// });
// };
// }
// return this.task;
// }
// }


export class CxTopicControlBar extends CxTaskControlBar {
public defaultBtn() {
Expand Down Expand Up @@ -74,6 +43,7 @@ export class TopicAdapter extends Task {
Application.App.log.Debug("题目信息", this.taskinfo);
this.topic.Init();
this.loadCallback && this.loadCallback();
resolve();
});
}

Expand Down
52 changes: 28 additions & 24 deletions src/mooc/chaoxing/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,36 @@ export class Video extends Task {
protected afterPoint: number = 0;
protected flash: boolean;

public Init() {
Application.App.log.Debug("播放器配置", this.taskinfo);
let timer = this.context.setInterval(() => {
try {
let video = this.context.document.getElementById("video_html5_api");
if (video == undefined) {
if (this.context.document.querySelector("#reader").innerHTML.indexOf("您没有安装flashplayer") >= 0) {
this.context.clearInterval(timer);
this.flash = true;
this.loadCallback && this.loadCallback();
public Init(): Promise<any> {
return new Promise(resolve => {
Application.App.log.Debug("播放器配置", this.taskinfo);
let timer = this.context.setInterval(() => {
try {
let video = this.context.document.getElementById("video_html5_api");
if (video == undefined) {
if (this.context.document.querySelector("#reader").innerHTML.indexOf("您没有安装flashplayer") >= 0) {
this.context.clearInterval(timer);
this.flash = true;
this.loadCallback && this.loadCallback();
resolve();
}
return;
}
return;
this.context.clearInterval(timer);
this.video = video;
this.initPlayer();
this.video.addEventListener("ended", () => {
this.completeCallback && this.completeCallback();
});
this.video.addEventListener("pause", () => {
Application.App.config.auto && this.video.play();
});
this.loadCallback && this.loadCallback();
resolve();
} catch (error) {
}
this.context.clearInterval(timer);
this.video = video;
this.initPlayer();
this.video.addEventListener("ended", () => {
this.completeCallback && this.completeCallback();
});
this.video.addEventListener("pause", () => {
Application.App.config.auto && this.video.play();
});
this.loadCallback && this.loadCallback();
} catch (error) {
}
}, 500);
}, 500);
});
}

public Start(): void {
Expand Down
44 changes: 29 additions & 15 deletions src/mooc/course163/course163.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Mooc } from "../factory";
import { Hook, Context } from "@App/internal/utils/hook";
import { createBtn, substrex, protocolPrompt } from "@App/internal/utils/utils";
import {Mooc} from "../factory";
import {Hook, Context} from "@App/internal/utils/hook";
import {createBtn, substrex, protocolPrompt} from "@App/internal/utils/utils";
import "../../views/common";
import { CourseTopic, CourseQueryAnswer } from "./question";
import { ToolsQuestionBankFacade, ToolsQuestionBank, QuestionBank, QuestionBankFacade, Answer, Option, PushAnswer } from "@App/internal/app/question";
import { Application } from "@App/internal/application";
import {CourseTopic, CourseQueryAnswer} from "./question";
import {
ToolsQuestionBankFacade,
ToolsQuestionBank,
QuestionBank,
QuestionBankFacade,
Answer,
Option,
PushAnswer,
QuestionStatusString
} from "@App/internal/app/question";
import {Application} from "@App/internal/application";

export class Course163 implements Mooc {

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

search.innerText = "搜索中...";
search.innerText = await topic.QueryAnswer();
search.innerText = "搜索答案";
let ret = await topic.QueryAnswer();
search.innerText = QuestionStatusString(ret);
}
divel.insertBefore(search, divel.firstChild);
}
Expand Down Expand Up @@ -94,7 +107,7 @@ export class Course163 implements Mooc {
tmpAnswer.topic = topic.title;
tmpAnswer.type = 4;
tmpAnswer.correct = new Array<Option>();
if(!topic.stdAnswer){
if (!topic.stdAnswer) {
continue;
}
tmpAnswer.correct.push({
Expand All @@ -106,13 +119,14 @@ export class Course163 implements Mooc {
tmpAnswer.topic = topic.title;
tmpAnswer.type = 3;
tmpAnswer.correct = new Array<Option>();
if(!topic.optionDtos){
if (!topic.optionDtos) {
continue;
}
for (let n = 0; n < topic.optionDtos.length; n++) {
if (topic.optionDtos[n].answer) {
tmpAnswer.correct.push({
option: "正确" == topic.optionDtos[n].content, content: "正确" == topic.optionDtos[n].content,
option: "正确" == topic.optionDtos[n].content,
content: "正确" == topic.optionDtos[n].content,
});
break;
}
Expand All @@ -121,7 +135,7 @@ export class Course163 implements Mooc {
}
continue;
}
if(!topic.optionDtos){
if (!topic.optionDtos) {
continue;
}
let option = new Array<Option>();
Expand All @@ -130,7 +144,7 @@ export class Course163 implements Mooc {
tmpAnswer.topic = topic.title;
tmpAnswer.type = topic.type;
for (let i = 0; i < topic.optionDtos.length; i++) {
let opt = { content: topic.optionDtos[i].content, option: String.fromCharCode(65 + i) };
let opt = {content: topic.optionDtos[i].content, option: String.fromCharCode(65 + i)};
if (topic.optionDtos[i].answer) {
correct.push(opt);
}
Expand Down
39 changes: 28 additions & 11 deletions src/mooc/zhihuishu/exam.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { Mooc } from "../factory";
import { createBtn, substrex, randNumber, protocolPrompt } from "@App/internal/utils/utils";
import {Mooc} from "../factory";
import {createBtn, substrex, randNumber, protocolPrompt} from "@App/internal/utils/utils";
import "../../views/common";
import { Topic, QueryQuestions } from "@App/internal/app/topic";
import { Question, ToolsQuestionBankFacade, ToolsQuestionBank, TopicType, SwitchTopicType, TopicStatus, Answer, TopicStatusString, PushAnswer } from "@App/internal/app/question";
import { CreateNoteLine } from "../chaoxing/utils";
import {Topic, QueryQuestions} from "@App/internal/app/topic";
import {
Question,
ToolsQuestionBankFacade,
ToolsQuestionBank,
TopicType,
SwitchTopicType,
TopicStatus,
Answer,
TopicStatusString,
PushAnswer,
QuestionStatusString
} from "@App/internal/app/question";
import {CreateNoteLine} from "../chaoxing/utils";

//TODO: 与超星一起整合优化
export class ZhsExam implements Mooc {
Expand All @@ -18,10 +29,14 @@ export class ZhsExam implements Mooc {
this.topic.SetQueryQuestions(new ExamQueryQuestion());
window.addEventListener("load", () => {
setTimeout(() => {
document.oncontextmenu = () => { }
document.oncopy = () => { }
document.onpaste = () => { }
document.onselectstart = () => { }
document.oncontextmenu = () => {
}
document.oncopy = () => {
}
document.onpaste = () => {
}
document.onselectstart = () => {
}
if (document.querySelectorAll(".examInfo.infoList.clearfix").length <= 0) {
this.createBtn();
} else {
Expand All @@ -41,7 +56,7 @@ export class ZhsExam implements Mooc {

btn.innerText = "搜索中...";
let ret = await self.topic.QueryAnswer();
btn.innerText = ret;
btn.innerText = QuestionStatusString(ret);
return false;
}
}
Expand All @@ -64,7 +79,8 @@ class ExamQueryQuestion implements QueryQuestions {

protected createQuestion(type: TopicType, el: HTMLElement): Question {
switch (type) {
case 1: case 2: {
case 1:
case 2: {
return new ZhsSelectQuestion(el, type);
}
case 3: {
Expand All @@ -81,6 +97,7 @@ class ExamQueryQuestion implements QueryQuestions {
abstract class ZhsQuestion implements Question {
protected el: HTMLElement;
protected type: TopicType;

constructor(el: HTMLElement, type: TopicType) {
this.el = el;
this.type = type;
Expand Down
1 change: 1 addition & 0 deletions src/tampermonkey/cxmooc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// @match *://*/work/selectWorkQuestionYiPiYue?*
// @match *://*/work/doHomeWorkNew?*
// @match *://*/ananas/modules/video/index.html?*
// @match *://*.chaoxing.com/exam/test?*
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @license MIT
Expand Down

0 comments on commit 2c9a435

Please sign in to comment.