forked from RainySY/chaoxing-xuexitong-autoflush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
98 lines (85 loc) · 2.41 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
console.log("版权声明:");
console.log("作者: Wyatt Zheng");
console.log("邮箱: [email protected]");
console.log("\n");
console.log("本作品仅提供学习及研究程序原理用途\n\n");
const fs = require("fs");
let Loginer = require("./loginer.js");
let task = require("./courseTask.js");
let prompt = require("prompts");
let coursepicker = require("./coursepicker.js");
let Net = require("./net.js");
let Config = require("./config.js");
async function getUser(cookie) {
let domain = "https://mooc1-1.chaoxing.com/";
let net = new Net(domain);
await net.setCookie(cookie);
let userid = Net.parseCookies(cookie)["_uid"];
let user = {
userid: userid,
cookie,
net,
};
return user;
}
async function start() {
let config = await new Config("./config.json").read();
let cookie;
// if (config.saveCookie) {
// // 尝试读取 cookie.txt 来使用
// if (fs.existsSync("./cookie.txt")) {
// cookie = fs.readFileSync("./cookie.txt");
// } else {
// // 没找到 cookie.txt 尝试登陆并保存
// console.log("没有已经保存的Cookie 将登陆获取一个");
// cookie = await new Loginer().login(config);
// fs.writeFileSync("./cookie.txt", cookie.toString());
// }
// } else {
// // 没有开启 Cookie 保存,那就每次都登陆
// cookie = await new Loginer().login(config);
// }
cookie = await new Loginer().login(config);
let user = await getUser(cookie);
// console.log(cookie);
console.log("\n");
if (!config.speed) {
Object.assign(
config,
await prompt({
type: "number",
name: "speed",
message: "请输入视频刷课速率(不填默认为2)",
})
);
}
if (!config.speed) config.speed = 2.0;
let picker = new coursepicker(user);
let courses = await picker.pick(config);
if (!courses.length) {
console.log("似乎没有课程可用, 程序已退出");
return;
}
console.log("\n");
if (!config.test) {
Object.assign(
config,
await prompt({
type: "text",
name: "test",
message: "默认自动过测验,若需要关闭该功能请填写 no 并回车",
})
);
}
let autotest = config.test == "no" ? false : true;
// console.log(courses);
new task(courses, user, config.speed, config.autotest);
}
async function debug(cookie) {
let user = await getUser(cookie);
let speed = 16.0;
let picker = new coursepicker(user);
await picker.getAllCourses();
new task(picker.list.slice(6), user, speed);
}
start().catch(console.log);