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

Commit f71a71a

Browse files
committed
支持CAT_click & 修复油猴脚本问题 & fix: #219 #218
1 parent 7c71874 commit f71a71a

File tree

7 files changed

+56
-25
lines changed

7 files changed

+56
-25
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"description": "一个 大学生网课 学习工具,火狐,谷歌,油猴支持.全自动任务,视频倍速秒过,作业考试题库,验证码自动打码(੧ᐛ੭挂科模式,启动)",
55
"main": "mooc.js",
66
"scripts": {
7-
"test": "node_modules/.bin/jest",
8-
"build": "node_modules/.bin/webpack --mode production --config webpack.config.js",
9-
"tampermonkey": "node_modules/.bin/webpack --mode development --config webpack.tampermonkey.js",
10-
"dev": "node_modules/.bin/webpack --mode development --config webpack.dev.js",
11-
"pack": "node_modules/.bin/tsc src/internal/pack-crx.ts && node src/internal/pack-crx.js",
12-
"docs:dev": "node_modules/.bin/vuepress dev docs",
13-
"docs:build": "node_modules/.bin/vuepress build docs"
7+
"test": "jest",
8+
"build": "webpack --mode production --config webpack.config.js",
9+
"tampermonkey": "webpack --mode development --config webpack.tampermonkey.js",
10+
"dev": "webpack --mode development --config webpack.dev.js",
11+
"pack": "tsc src/internal/pack-crx.ts && node src/internal/pack-crx.js",
12+
"docs:dev": "vuepress dev docs",
13+
"docs:build": "vuepress build docs"
1414
},
1515
"repository": {
1616
"type": "git",

src/internal/utils/config.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {boolToString, randNumber, toBool} from "./utils";
2-
import {Application} from "../application";
3-
import {SystemConfig} from "@App/config";
1+
import { boolToString, randNumber, toBool } from "./utils";
2+
import { Application } from "../application";
3+
import { SystemConfig } from "@App/config";
44

55
export interface ConfigItems extends Config {
66
SetNamespace(namespace: string): void
@@ -222,7 +222,7 @@ class backendConfig implements Config {
222222
// 更新配置转为json,存入
223223
protected updateConfigStorage() {
224224
let txt = JSON.stringify(this.cache);
225-
chrome.storage.sync.set({"config_storage": txt});
225+
chrome.storage.sync.set({ "config_storage": txt });
226226
}
227227

228228
// 更新缓存
@@ -240,7 +240,7 @@ class backendConfig implements Config {
240240
}
241241
});
242242
this.updateConfigStorage();
243-
resolve();
243+
resolve(undefined);
244244
});
245245
});
246246
}
@@ -263,12 +263,12 @@ class backendConfig implements Config {
263263
info[key] = val;
264264
//通知前端和后端
265265
this.cache[key] = val;
266-
chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
267-
chrome.tabs.sendMessage(tabs[0].id, {type: "cxconfig", key: key, value: val});
266+
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
267+
chrome.tabs.sendMessage(tabs[0].id, { type: "cxconfig", key: key, value: val });
268268
});
269-
chrome.runtime.sendMessage({type: "cxconfig", key: key, value: val});
269+
chrome.runtime.sendMessage({ type: "cxconfig", key: key, value: val });
270270
this.updateConfigStorage();
271-
resolve();
271+
resolve(undefined);
272272
});
273273
}
274274

@@ -295,7 +295,7 @@ class frontendGetConfig implements Config {
295295

296296
constructor() {
297297
this.watch = new configWatch();
298-
this.cache = (<any>window).configData;
298+
this.cache = (<any>window).configData || localStorage;
299299
window.addEventListener('message', (event) => {
300300
if (event.data.type && event.data.type == "cxconfig") {
301301
Application.App.log.Info("配置更新:" + event.data.key + "=" + event.data.value);
@@ -322,7 +322,7 @@ class frontendGetConfig implements Config {
322322
return (<any>window).GM_setValue(key, val);
323323
}
324324
return Application.App.Client.Send({
325-
type: "GM_setValue", details: {key: key, val: val},
325+
type: "GM_setValue", details: { key: key, val: val },
326326
});
327327
}
328328

src/internal/utils/log.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,25 @@ export class PageLog implements Logger {
138138
return parseInt(window.getComputedStyle(ele)[prop]);
139139
}
140140

141-
this.div.style.left = Application.App.config.GetConfig("notify_tools_x");
142-
this.div.style.top = Application.App.config.GetConfig("notify_tools_y");
141+
const windowWidth = window.innerWidth;
142+
const windowHeight = window.innerHeight;
143+
const containerWidth = getProperty(this.div, "width");
144+
const containerHeight = getProperty(this.div, "height");
145+
let x = parseInt(Application.App.config.GetConfig("notify_tools_x").replace('px', ''));
146+
if (x < 0) {
147+
x = 0;
148+
}
149+
if (x >= windowWidth - containerWidth)
150+
x = windowWidth - containerWidth;
151+
this.div.style.left = x + "px";
152+
let y = parseInt(Application.App.config.GetConfig("notify_tools_y").replace('px', ''));
153+
if (y < 0) {
154+
y = 0;
155+
}
156+
if (y >= windowHeight - containerHeight)
157+
y = windowHeight - containerHeight;
158+
this.div.style.top = y + "px";
159+
143160
let head = <HTMLElement>this.div.querySelector("#tools-head");
144161
head.onmousedown = (downEvent) => {
145162
let relaX = downEvent.clientX - this.div.offsetLeft;

src/internal/utils/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ export function boolToString(val: boolean): string {
419419
}
420420

421421
export function UntrustedClick(el: Element): boolean {
422+
if (window.CAT_click != undefined) {
423+
CAT_click(el);
424+
return true;
425+
}
422426
let untrusted = new MouseEvent("click", { "clientX": 10086 });
423427
if (!untrusted.isTrusted) {
424428
Application.App.log.Warn("扩展执行错误");

src/mooc/chaoxing/task.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {CssBtn} from "@App/mooc/chaoxing/utils";
2-
import {createBtn} from "@App/internal/utils/utils";
3-
import {Application} from "@App/internal/application";
4-
import {Task, TaskEvent} from "@App/internal/app/task";
1+
import { CssBtn } from "@App/mooc/chaoxing/utils";
2+
import { createBtn, get } from "@App/internal/utils/utils";
3+
import { Application } from "@App/internal/application";
4+
import { Task, TaskEvent } from "@App/internal/app/task";
55

66
export abstract class CxTask extends Task {
77
public jobIndex: number;
@@ -96,7 +96,13 @@ export class CxTaskControlBar {
9696
let download = CssBtn(createBtn("下载资源", "我要下载下来好好学习", "cx-btn"));
9797
download.style.background = "#999999";
9898
download.onclick = () => {
99-
window.open("http://d0.ananas.chaoxing.com/download/" + this.task.taskinfo.property.objectid);
99+
(<any>get("https://mooc1-1.chaoxing.com/ananas/status/" + this.task.taskinfo.property.objectid, (data: string) => {
100+
let json = JSON.parse(data);
101+
prompt("如果打开下载失败,请复制下面链接手动下载", json.download);
102+
window.open(json.download);
103+
})).error(() => {
104+
alert("资源信息获取失败");
105+
});
100106
};
101107
return download;
102108
}

src/tampermonkey/course163.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// @match *://www.icourse163.org/spoc/learn/*
1010
// @grant GM_xmlhttpRequest
1111
// @grant GM_notification
12+
// @grant CAT_click
1213
// @grant unsafeWindow
1314
// @license MIT
1415
// ==/UserScript==

src/tools.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
declare function CAT_click(el: Element): void;
3+

0 commit comments

Comments
 (0)