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

Commit

Permalink
兼容油猴bug和firefox兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jun 27, 2021
1 parent 6d77de1 commit 21bcf9d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/internal/application.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Client, NewChromeClientMessage, NewExtensionClientMessage} from "./utils/message";
import {HttpUtils} from "./utils/utils";
import {ConfigItems} from "./utils/config";
import {Logger} from "./utils/log";
import {SystemConfig} from "@App/config";
import {QuestionBank} from "./app/question";
import { Client, NewChromeClientMessage, NewExtensionClientMessage } from "./utils/message";
import { HttpUtils } from "./utils/utils";
import { ConfigItems } from "./utils/config";
import { Logger } from "./utils/log";
import { SystemConfig } from "@App/config";
import { QuestionBank } from "./app/question";

export const Backend = "backend";
export const Frontend = "frontend";
Expand Down Expand Up @@ -108,7 +108,7 @@ export class Application {
hotversion: json.hotversion,
injection: json.injection,
};
chrome.storage && chrome.storage.local.set(data);
Application.IsContent && chrome.storage.local.set(data);
await callback((SystemConfig.version < data.version), data);
}, error: async function () {
await callback(false, undefined);
Expand Down
4 changes: 2 additions & 2 deletions src/internal/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ export class PageLog implements Logger {
const windowHeight = window.innerHeight;
const containerWidth = getProperty(this.div, "width");
const containerHeight = getProperty(this.div, "height");
let x = parseInt(Application.App.config.GetConfig("notify_tools_x").replace('px', ''));
let x = parseInt(Application.App.config.GetConfig("notify_tools_x", "60px").replace('px', ''));
if (x < 0) {
x = 0;
}
if (x >= windowWidth - containerWidth)
x = windowWidth - containerWidth;
this.div.style.left = x + "px";
let y = parseInt(Application.App.config.GetConfig("notify_tools_y").replace('px', ''));
let y = parseInt(Application.App.config.GetConfig("notify_tools_y", "40px").replace('px', ''));
if (y < 0) {
y = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mooc/chaoxing/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CxCourse extends EventListener<MoocEvent> implements MoocTaskSet {
Application.App.log.Info("超星新窗口加载");
this.OperateCard(el);
// 超星会有多次加载,所以使用一个flag变量,只回调一次
first && resolve();
first && resolve(undefined);
first = false;
}
}, true);
Expand Down
28 changes: 19 additions & 9 deletions src/mooc/chaoxing/question.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {substrex, randNumber as RandNumber, removeHTMLTag} from "@App/internal/utils/utils";
import { substrex, randNumber as RandNumber, removeHTMLTag } from "@App/internal/utils/utils";
import {
Question,
TopicStatus,
Expand All @@ -9,7 +9,7 @@ import {
Answer,
PushAnswer
} from "@App/internal/app/question";
import {CreateNoteLine} from "./utils";
import { CreateNoteLine } from "./utils";

//TODO: 优化
export class CxQuestionFactory {
Expand Down Expand Up @@ -356,21 +356,31 @@ class cxJudgeQuestion extends cxSelectQuestion implements Question {
public Correct(): Answer {
let el = this.el.querySelector(".Py_answer.clearfix");
let ret = this.defaultAnswer();
if (el.querySelectorAll('.fr.dui').length <= 0 && el.querySelectorAll('.fr.cuo').length <= 0) {
let score = this.el.querySelector(".Cy_TItle.clearfix .font18.fb");
if (el.innerHTML.indexOf('正确答案') !== -1 || (score && score.querySelector(".Cy_TItle.clearfix .font18.fb").innerHTML != "0.0")) {
let correctText = el.querySelector("span").innerText;
if (correctText.indexOf('×') !== -1) {
ret.correct.push({ option: false, content: false });
} else {
ret.correct.push({ option: true, content: true });
}
return ret;
}
if (!el.querySelectorAll('.fr.dui').length && !el.querySelectorAll('.fr.cuo').length) {
return null;
}
let correctText = el.querySelector("span").innerText;
if (el.querySelectorAll('.fr.dui').length) {
if (correctText.indexOf('×') >= 0) {
ret.correct.push({option: false, content: false});
if (correctText.indexOf('×') !== -1) {
ret.correct.push({ option: false, content: false });
} else {
ret.correct.push({option: true, content: true});
ret.correct.push({ option: true, content: true });
}
} else {
if (correctText.indexOf('×') >= 0) {
ret.correct.push({option: true, content: true});
if (correctText.indexOf('×') !== -1) {
ret.correct.push({ option: true, content: true });
} else {
ret.correct.push({option: false, content: false});
ret.correct.push({ option: false, content: false });
}
}
return ret;
Expand Down
8 changes: 4 additions & 4 deletions src/mooc/chaoxing/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TopicAdapter extends CxTask {
return new Promise<any>(async resolve => {
Application.App.log.Debug("题目信息", this.taskinfo);
await this.topic.Init();
resolve();
resolve(undefined);
});
}

Expand Down Expand Up @@ -117,7 +117,7 @@ export class CxCourseTopic extends Topic {
if (this.context.document.URL.indexOf("selectWorkQuestionYiPiYue") > 0) {
await this.CollectAnswer();
}
resolve();
resolve(undefined);
}
}, 500);
});
Expand Down Expand Up @@ -156,7 +156,7 @@ export class CxCourseTopic extends Topic {
.addEventListener("load", async function () {
if (this.contentWindow.document.URL.indexOf('selectWorkQuestionYiPiYue') > 0) {
await self.CollectAnswer();
resolve();
resolve(undefined);
}
});
//确定提交
Expand Down Expand Up @@ -192,7 +192,7 @@ export class ExamTopic extends Topic implements QueryQuestions {

public Submit(): Promise<any> {
return new Promise(resolve => {
resolve();
resolve(undefined);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tampermonkey/course163.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// ==/UserScript==

let config = {
answer_ignore: true, //忽略题目,勾选此处将不会答题
answer_ignore: false, //忽略题目,勾选此处将不会答题
auto: true, //全自动挂机,无需手动操作,即可自动观看视频等
rand_answer: false, //随机答案,没有答案的题目将自动的生成一个答案
interval: 1, //时间间隔,当任务点完成后,会等待1分钟然后跳转到下一个任务点
Expand Down
2 changes: 1 addition & 1 deletion src/tampermonkey/cxmooc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// ==/UserScript==

let config = {
answer_ignore: true, //忽略题目,勾选此处将不会答题
answer_ignore: false, //忽略题目,勾选此处将不会答题
auto: true, //全自动挂机,无需手动操作,即可自动观看视频等
interval: 1, //时间间隔,当任务点完成后,会等待1分钟然后跳转到下一个任务点
rand_answer: false, //随机答案,没有答案的题目将自动的生成一个答案
Expand Down

0 comments on commit 21bcf9d

Please sign in to comment.