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 Oct 27, 2020
1 parent c392f9e commit 46842cb
Show file tree
Hide file tree
Showing 28 changed files with 4,925 additions and 5,448 deletions.
174 changes: 89 additions & 85 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,92 +9,96 @@
// }

module.exports = {
title: '超星慕课小工具',
base: '/',
themeConfig: {
nav: [
{ text: '首页', link: '/' },
{
text: '使用教程',
items: [
{ text: '简介', link: '/1-UserGuide/' },
{ text: '打包版浏览器(小白看我)', link: '/1-UserGuide/1-7-easychorme.md' },
{ text: 'FireFox 扩展', link: '/1-UserGuide/1-2-firefox.html' },
{ text: 'Chrome 扩展', link: '/1-UserGuide/1-1-chrome.html' },
{ text: 'Tampermonkey 脚本', link: '/1-UserGuide/1-3-tampermonkey.html' },
{ text: '中国大学mooc专用', link: '/1-UserGuide/1-8-moocchorme.html' },
{ text: '常见问题【使用必看】', link: '/1-UserGuide/qa.md' },
{ text: '功能说明', link: '/1-UserGuide/featured.html' },
{ text: '配置说明', link: '/1-UserGuide/1-4-config.html' },
]
},
{ text: '开发文档', link: '/Develop/' },
{ text: '免责声明', link: '/3-Disclaimer/' },
{
text: '语言选项',
items: [
{ text: '简体中文', link: '/' },
{ text: 'English', link: '/en-us/' }
]
},
//{ text: 'Github', link: 'https://github.com/CodFrm/cxmooc-tools' },
],
// sidebar: 'auto',
sidebar: {
'/1-UserGuide/': [
'',
'qa.html',
'1-6-gettoken.html',
'1-7-easychorme.html',
'1-8-moocchorme.html',
'1-2-firefox.html', /* /foo/one.html */
'1-1-chrome.html',
'1-3-tampermonkey.html', /* /foo/ */
'1-5-otherchorme.html',
'featured.html',//功能说明
'1-4-config.html',//配置说明
],
'/Develop/': [
'',
],
},
serviceWorker: {
updatePopup: true, // Boolean | Object, 默认值是 undefined.
// 如果设置为 true, 默认的文本配置将是:
// updatePopup: {
// message: "New content is available.",
// buttonText: "Refresh"
// }
updatePopup: {
message: "文档有更新,新的内容已准备就绪",
buttonText: "刷新获取新内容"
}
},
// 假定是 GitHub. 同时也可以是一个完整的 GitLab URL
repo: 'CodFrm/cxmooc-tools',
// 自定义仓库链接文字。默认从 `themeConfig.repo` 中自动推断为
// "GitHub"/"GitLab"/"Bitbucket" 其中之一,或是 "Source"。
repoLabel: 'GitHub',
title: '超星慕课小工具',
base: '/',
themeConfig: {
nav: [
{text: '首页', link: '/'},
{
text: '使用教程',
items: [
{text: '简介', link: '/1-UserGuide/'},
{text: '打包版浏览器(小白看我)', link: '/1-UserGuide/1-7-easychorme.md'},
{text: 'FireFox 扩展', link: '/1-UserGuide/1-2-firefox.html'},
{text: 'Chrome 扩展', link: '/1-UserGuide/1-1-chrome.html'},
{text: 'Tampermonkey 脚本', link: '/1-UserGuide/1-3-tampermonkey.html'},
{text: '中国大学mooc专用', link: '/1-UserGuide/1-8-moocchorme.html'},
{text: '常见问题【使用必看】', link: '/1-UserGuide/qa.md'},
{text: '功能说明', link: '/1-UserGuide/featured.html'},
{text: '配置说明', link: '/1-UserGuide/1-4-config.html'},
]
},
{text: '开发文档', link: '/Develop/'},
{text: '免责声明', link: '/3-Disclaimer/'},
{
text: '语言选项',
items: [
{text: '简体中文', link: '/'},
{text: 'English', link: '/en-us/'}
]
},
//{ text: 'Github', link: 'https://github.com/CodFrm/cxmooc-tools' },
],
// sidebar: 'auto',
sidebar: {
'/1-UserGuide/': [
'',
'qa.html',
'1-6-gettoken.html',
'1-7-easychorme.html',
'1-8-moocchorme.html',
'1-2-firefox.html', /* /foo/one.html */
'1-1-chrome.html',
'1-3-tampermonkey.html', /* /foo/ */
'1-5-otherchorme.html',
'featured.html',//功能说明
'1-4-config.html',//配置说明
],
'/Develop/': [
'',
'Component.html',
'Platform.html',
'QuestionBank.html',
'Utils.html'
],
},
serviceWorker: {
updatePopup: true, // Boolean | Object, 默认值是 undefined.
// 如果设置为 true, 默认的文本配置将是:
// updatePopup: {
// message: "New content is available.",
// buttonText: "Refresh"
// }
updatePopup: {
message: "文档有更新,新的内容已准备就绪",
buttonText: "刷新获取新内容"
}
},
// 假定是 GitHub. 同时也可以是一个完整的 GitLab URL
repo: 'CodFrm/cxmooc-tools',
// 自定义仓库链接文字。默认从 `themeConfig.repo` 中自动推断为
// "GitHub"/"GitLab"/"Bitbucket" 其中之一,或是 "Source"。
repoLabel: 'GitHub',

// 以下为可选的编辑链接选项
// 以下为可选的编辑链接选项

// 假如文档不是放在仓库的根目录下:
docsDir: 'docs',
// 假如文档放在一个特定的分支下:
docsBranch: 'master',
// 默认是 false, 设置为 true 来启用
editLinks: true,
// 默认为 "Edit this page"
editLinkText: '在 GitHub 上编辑此页',
lastUpdated: 'Last Updated', // string | boolean
},
plugins: [
['@vuepress/back-to-top'],
[
'@vuepress/google-analytics',
{
'ga': 'UA-138255059-2'
}
// 假如文档不是放在仓库的根目录下:
docsDir: 'docs',
// 假如文档放在一个特定的分支下:
docsBranch: 'master',
// 默认是 false, 设置为 true 来启用
editLinks: true,
// 默认为 "Edit this page"
editLinkText: '在 GitHub 上编辑此页',
lastUpdated: 'Last Updated', // string | boolean
},
plugins: [
['@vuepress/back-to-top'],
[
'@vuepress/google-analytics',
{
'ga': 'UA-138255059-2'
}
]
]
]
}
Binary file added docs/.vuepress/public/img/生命周期.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions docs/Develop/Component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: 内置组件
---

> 为了方便开发,提供了很多内置组件来进行调用,每一个组件都提供了接口可以定制化
>
> 存放文件夹为`internal/utils`
在应用启动(mooc.ts)周期注入组件实例
```ts
let component = new Map<string, any>()
.set("config", new ChromeConfigItems(NewFrontendGetConfig()))
.set("logger", logger);
```

## 日志组件
方便采集日志,未来可以对一些严重的日志进行采集,分析bug出现情况

#### 接口
```ts
export interface Logger {
Debug(...args: any[]): Logger;

Info(...args: any[]): Logger;

Warn(...args: any[]): Logger;

Error(...args: any[]): Logger;

Fatal(...args: any[]): Logger;
}
```
#### 实现
ConsoleLog console处打印日志内容

PageLog 会在窗口显示日志内容,并且根据等级不同会进行消息通知

#### 使用
```ts
Application.App.log.Error("获取题目发生了一个错误", e);
```

## 配置组件
应用配置,可以根据配置调整运行状态,也可作为一个存储组件使用,不过请勿存储较长内容

Config为配置基础接口,主要存储和监听配置kv

ConfigItems具体配置项
#### 接口
```ts
export interface Config {
GetConfig(key: string, defaultVal?: string): string

SetConfig(key: string, val: string): Promise<any>

ConfigList(): any

Watch(key: Array<string> | string, callback: ConfigWatchCallback): void
}

export interface ConfigItems extends Config {
SetNamespace(namespace: string): void

SetNamespaceConfig(namespace: string, key: string, val: string): Promise<any>

GetNamespaceConfig(namespace: string, key: string, defaultVal?: string): string

vtoken: string
rand_answer: boolean
auto: boolean
video_mute: boolean
answer_ignore: boolean
video_cdn: string
video_multiple: number
interval: number
topic_interval: number
super_mode: boolean
}
```
#### 实现
ChromeConfigItems 具体配置项类,需要注入具体Config实例实现存储功能

backendConfig 在扩展的后端环境使用

frontendGetConfig 在扩展的前端环境使用
#### 使用

```ts
new ChromeConfigItems(NewFrontendGetConfig())
// 对于配置类的可以直接定义新的配置项
Application.App.config.auto
Application.App.config.auto=false
// 更偏向于储存的可以直接使用自定义key,不过请注意,不要存储过长的内容
Application.App.config.GetConfig("notify_tools_x")
Application.App.config.SetConfig("notify_tools_x", this.div.style.left);
```

#### 增减配置和关联配置面板
增减配置需要修改`config.ts:configDefaultValue`,`config.ts:ConfigItems`接口与实现

配置面板中:`views/popup.ts:popup:start:configs`,具体可看现有配置

如果发布油猴版本,请在对应的油猴版本中添加相应的配置


30 changes: 30 additions & 0 deletions docs/Develop/Platform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: 平台开发
---

> 为了方便开发,抽象了平台的流程,只需要专注于功能的实现
## 开始
创建新的平台应该遵循现有规则,在`mooc`文件夹下创建以平台为命名规则的文件夹

且有文件`mooc/[platform]/platform.ts`,实现`MoocFactory`接口的类,用于通过页面信息来创建对应的具体`Mooc`对象,如果不符合规则返回`null`,对应`构建实例(mooc/[platform]/platform.ts)`生命周期

需要在`/build/cxmooc-tools/manifest.json`文件和`/src/config.ts`中添加对应的URL规则

如果你需要开发油猴脚本,那么你需要在`/src/tampermonkey`目录中添加对应的油猴文件,且在`webpack.tampermonkey.js``internal/pack-crx.ts:43`中添加对应配置,具体请参考现有平台


## 实现Mooc接口
还在优化中,具体请看已有平台

#### 接口定义
```ts
export interface Mooc {
Init(): void
// TODO: 实现各种流程流转
// Start()
// Stop()
// OnFinished()
// Next()
}
```
73 changes: 73 additions & 0 deletions docs/Develop/QuestionBank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: 题库和答题功能
---

> 扩展抽象了题库,方便切换或者增加题库使用
>
> 源码请看`internal/app/question.ts``internal/app/topic.ts`
> ps:这个模块其实挺乱的...想优化
## 题库接口
题库的接口
```ts
// 题库操作具体实现
export interface QuestionBankFacade {
ClearQuestion(): void

AddQuestion(q: Question): void

Answer(callback: (status: QuestionStatus) => void): void

Push(callback: (status: QuestionStatus) => void): void

CheckCourse(): Promise<number>
}
// 题库存储具体实现
export interface QuestionBank {
Answer(topic: Topic[], resolve: QuestionBankCallback): void;

Push(answer: Answer[]): Promise<QuestionStatus>;

SetInfo(info: QuestionInfo): void;

CheckCourse?(info?: QuestionInfo[]): Promise<number>;
}
```
#### 实现
ToolsQuestionBankFacade 扩展自带题库

#### 使用
```ts
let topic = new ExamTopic(context, new ToolsQuestionBankFacade("cx", taskinfo));
```

## 答题接口
如果是利用现在的题库,开发者只需要专注实现下列接口,具体可参考现有平台
```ts
// 选项
export interface Options {
Random(): TopicStatus;
Fill(s: Answer): Promise<TopicStatus>;
Correct(): Answer
}
// 题目,继承了选项接口
export interface Question extends Options {
GetType(): TopicType;
GetTopic(): string;
SetStatus(status: TopicStatus): void;
}
// 查询任务中的题目,返回Question数组
export interface QueryQuestions {
QueryQuestions(): Question[];
}
// 题目任务点
export abstract class Topic {
public abstract Init(): Promise<any>;
public abstract Submit(): Promise<any>;
}
```
#### 使用
```ts
let topic = new ExamTopic(context, new ToolsQuestionBankFacade("cx", taskinfo));

```
Loading

0 comments on commit 46842cb

Please sign in to comment.