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

Commit f9cf681

Browse files
committed
优化功能&修复163图片问题
1 parent 2844675 commit f9cf681

9 files changed

Lines changed: 59 additions & 43 deletions

File tree

build/cxmooc-tools/manifest.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
"48": "img/logo.png",
99
"128": "img/logo.png"
1010
},
11-
"applications": {
12-
"gecko": {
13-
"id": "love@xloli.top",
14-
"strict_min_version": "42.0"
15-
}
16-
},
1711
"browser_action": {
1812
"default_icon": "img/logo.png",
1913
"default_title": "超星慕课小工具",
@@ -53,6 +47,7 @@
5347
"permissions": [
5448
"tabs",
5549
"storage",
50+
"webNavigation",
5651
"<all_urls>"
5752
],
5853
"web_accessible_resources": [

src/background.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ class background implements Launcher {
2323
this.update();
2424
this.setDefaultConfig();
2525
this.injectedScript();
26+
this.event();
27+
}
28+
29+
protected event() {
30+
chrome.runtime.onInstalled.addListener((details) => {
31+
if (details.reason == "install") {
32+
chrome.tabs.create({ url: "https://cx.icodef.com/" });
33+
} else if (details.reason == "update") {
34+
chrome.tabs.create({ url: "https://github.com/CodFrm/cxmooc-tools/releases" });
35+
}
36+
});
2637
}
2738

2839
protected setDefaultConfig() {
@@ -78,13 +89,6 @@ class background implements Launcher {
7889
}
7990
this.source = this.dealScript(source, version);
8091
});
81-
if (Application.App.debug) {
82-
chrome.storage.onChanged.addListener((changes, namespace) => {
83-
if (namespace == "local" && changes["source"] != undefined) {
84-
this.source = this.dealScript(changes["source"].newValue, version);
85-
}
86-
});
87-
}
8892
});
8993
}
9094

@@ -99,30 +103,28 @@ class background implements Launcher {
99103
if (Application.App.debug) {
100104
return;
101105
}
102-
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
103-
if (changeInfo.status === 'loading' && changeInfo.url == null) {
104-
for (let i = 0; i < SystemConfig.match.length; i++) {
105-
let v = SystemConfig.match[i];
106-
v = v.replace(/(\.\?\/)/g, "\\$1");
107-
v = v.replace(/\*/g, ".*?");
108-
let reg = new RegExp(v);
109-
if (reg.test(tab.url)) {
110-
chrome.tabs.executeScript(tabId, {
111-
code: `(function(){
112-
let temp = document.createElement('script');
113-
temp.setAttribute('type', 'text/javascript');
114-
temp.innerHTML = "`+ this.source + `";
115-
temp.className = "injected-js";
116-
document.documentElement.appendChild(temp)
117-
}())`,
118-
allFrames: true,
119-
runAt: "document_start",
120-
});
121-
break;
122-
}
106+
chrome.webNavigation.onCommitted.addListener((details) => {
107+
for (let i = 0; i < SystemConfig.match.length; i++) {
108+
let v = SystemConfig.match[i];
109+
v = v.replace(/(\.\?\/)/g, "\\$1");
110+
v = v.replace(/\*/g, ".*?");
111+
let reg = new RegExp(v);
112+
if (reg.test(details.url)) {
113+
chrome.tabs.executeScript(details.tabId, {
114+
frameId: details.frameId,
115+
code: `(function(){
116+
let temp = document.createElement('script');
117+
temp.setAttribute('type', 'text/javascript');
118+
temp.innerHTML = "`+ this.source + `";
119+
temp.className = "injected-js";
120+
document.documentElement.appendChild(temp)
121+
}())`,
122+
runAt: "document_start",
123+
});
124+
break;
123125
}
124126
}
125-
});
127+
})
126128
}
127129
}
128130

src/internal/utils/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class PageLog implements Logger {
6060
this.el = undefined;
6161
window.addEventListener("load", () => {
6262
let div = document.createElement("div");
63-
div.innerHTML = '小工具通知条(😭丑陋)<button class="close">关闭</button><div class="tools-notice-content">';
63+
div.innerHTML = '小工具通知条<button class="close">关闭</button><div class="tools-notice-content">';
6464
div.className = "tools-logger-panel";
6565
document.body.appendChild(div);
6666
this.el = div.querySelector(".tools-notice-content");

src/internal/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export function removeHTML(html: string) {
285285
html = html.replace(revHtml, '');
286286
html = html.replace(/(^\s+)|(\s+$)/g, '');
287287
html = dealSymbol(html);
288-
return html.replace(/&nbsp;/g, ' ').trim();
288+
return html.replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&').trim();
289289
}
290290

291291
/**

src/mooc/chaoxing/video.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,16 @@ export class VideoFactory implements TaskFactory {
142142
prev.prepend(startBtn, pass, download, downloadSubtitle);
143143
// 绑定事件
144144
startBtn.onclick = () => {
145-
this.task.Start();
145+
if (startBtn.innerText == '挂机中...') {
146+
localStorage["auto"] = false;
147+
startBtn.innerText = "开始挂机";
148+
Application.App.log.Info("挂机停止了");
149+
} else {
150+
localStorage["auto"] = true;
151+
startBtn.innerText = '挂机中...';
152+
Application.App.log.Info("挂机开始了");
153+
this.task.Start();
154+
}
146155
};
147156
pass.onclick = () => {
148157
if (!protocolPrompt("秒过视频会产生不良记录,是否继续?", "boom_no_prompt")) {

src/mooc/course163/course163.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class Course163 implements Mooc {
8585
if (options == undefined) {
8686
return
8787
}
88+
//TODO:优化,太难看了
8889
for (let i = 0; i < options.length; i++) {
8990
let topic = options[i];
9091
if (topic.type != 1 && topic.type != 2) {
@@ -93,6 +94,9 @@ export class Course163 implements Mooc {
9394
tmpAnswer.topic = topic.title;
9495
tmpAnswer.type = 4;
9596
tmpAnswer.correct = new Array<Option>();
97+
if(!topic.stdAnswer){
98+
continue;
99+
}
96100
tmpAnswer.correct.push({
97101
option: "一", content: topic.stdAnswer,
98102
});
@@ -102,6 +106,9 @@ export class Course163 implements Mooc {
102106
tmpAnswer.topic = topic.title;
103107
tmpAnswer.type = 3;
104108
tmpAnswer.correct = new Array<Option>();
109+
if(!topic.optionDtos){
110+
continue;
111+
}
105112
for (let n = 0; n < topic.optionDtos.length; n++) {
106113
if (topic.optionDtos[n].answer) {
107114
tmpAnswer.correct.push({
@@ -114,6 +121,9 @@ export class Course163 implements Mooc {
114121
}
115122
continue;
116123
}
124+
if(!topic.optionDtos){
125+
continue;
126+
}
117127
let option = new Array<Option>();
118128
let correct = new Array<Option>();
119129
let tmpAnswer = new PushAnswer();

src/mooc/course163/question.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CourseQuestion implements Question {
8484

8585
protected dealImgDomain(content: string): string {
8686
//移除域名对比,也不知道还有没有花里胡哨的
87-
return content.replace(/"https:\/\/(.*?)\//, "\"");
87+
return content.replace(/"http(s|):\/\/(.*?)\//, "\"");
8888
}
8989

9090
public Fill(answer: Answer): TopicStatus {

src/tampermonkey/course163.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
2-
// @name 中国慕课小工具
2+
// @name 中国大学慕课小工具
33
// @namespace https://github.com/CodFrm/cxmooc-tools
4-
// @version 2.12
5-
// @description 一个中国大学慕课刷课工具,火狐,谷歌,油猴支持.自动作业测试题库(੧ᐛ੭挂科模式,启动)
4+
// @version 2.2.0
5+
// @description 一个中国大学mooc刷课工具,火狐,谷歌,油猴支持.自动作业测试题库(੧ᐛ੭挂科模式,启动)
66
// @author CodFrm
77
// @run-at document-start
88
// @match *://www.icourse163.org/learn/*

src/views/popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ <h4 class="one_title">
573573
<h4 class="one_title"><span>其他:</span></h4>
574574
<ul>
575575
<li><a class="three_font" href="https://github.com/CodFrm/cxmooc-tools" target="_black">GitHub开源地址</a></li>
576-
<li><a class="three_font" href="https://cx-doc.xloli.top" target="_black">使用文档</a></li>
576+
<li><a class="three_font" href="https://cx.icodef.com/" target="_black">使用文档</a></li>
577577
<li><a class="three_font" href="https://github.com/CodFrm/cxmooc-tools/issues"
578578
target="_black">Bug/意见/题目反馈地址</a>
579579
</li>

0 commit comments

Comments
 (0)