Skip to content

Commit

Permalink
fix: tasklist api
Browse files Browse the repository at this point in the history
  • Loading branch information
Xu22Web committed Mar 21, 2023
1 parent 527588c commit bbf2148
Show file tree
Hide file tree
Showing 46 changed files with 15,084 additions and 6,538 deletions.
26 changes: 1 addition & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

### 更新与维护 Update and Maintenance

1. 新增专项练习逆序,考虑到不同需求,能顺序或逆序查找到专项练习作答
1. 更新任务 API,新增响应式界面

2. 尝试修复同屏任务无效问题,由于问题原因未知,后续仍将继续修复

Expand All @@ -86,30 +86,6 @@

- [Docker 版](https://github.com/Xu22Web/tech-study-docker 'Docker 版')

### 公告 announcement

- **现征集在线题库,特此公告**

不知道大家有没有发现,在新版的脚本中,我将原本混乱的搜题`API`,替换成了自行整合的搜题`API`

由于以下原因:

1. 答题需要收集和优化题库,方便搜题请求

2. 便于其他方式的调用,目前,搜题`API`的题库有`7`

存在的问题:

1. 题量有限

2. 准确度欠佳

- 如果大家发现新的题库或者对于题库有何建议,可以去下面的仓库反馈

- 关于题库: [answer-search-bank](https://github.com/Xu22Web/answer-search-bank) `https://github.com/Xu22Web/answer-search-bank`

最后,希望在大家的帮助下,提供更高质量、更优质的脚本!

### 关于开发 Development

- 脚本配置
Expand Down
2 changes: 1 addition & 1 deletion cache.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"homepage": "https://github.com/Xu22Web/tech-study-js#readme",
"devDependencies": {
"@rollup/plugin-terser": "^0.4.0",
"@types/node": "^18.13.0",
"@types/node": "^18.14.6",
"@types/tampermonkey": "^4.0.10",
"chalk": "^4.1.2",
"ora": "^4.1.1",
"rollup": "^3.15.0",
"rollup": "^3.18.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
}
Expand Down
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 23 additions & 15 deletions src/api/answer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import API_CONFIG from '../config/api';
import { log } from '../utils/log';
/* 答案 API */

/**
Expand All @@ -7,29 +8,36 @@ import API_CONFIG from '../config/api';
async function getAnswer(question: string) {
// 数据
const data = {
question,
txt_name: md5(question),
password: '',
};
try {
const params = new URLSearchParams(data);
// 请求
const res = await fetch(API_CONFIG.answerSearch, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify(data),
body: params.toString(),
});
// 请求成功
if (res.ok) {
const data: {
errno: number;
data: { answers: string[] };
} = await res.json();
// 状态
const { errno } = data;
if (errno !== -1) {
const result = await res.json();
const { data, status } = <
{
status: number;
data: { txt_content: string; txt_name: string };
}
>result;
if (status !== 0) {
// 答案列表
const answerList: { content: string; title: string }[] = JSON.parse(
data.txt_content
);
// 答案
const { answers } = data.data;
const answers = answerList[0].content.split(/[;\s]/);
return answers;
}
}
Expand All @@ -40,13 +48,13 @@ async function getAnswer(question: string) {
/**
* @description 保存答案
*/
async function saveAnswer(key, value) {
async function saveAnswer(question: string, answer: string) {
try {
// 内容
const content = JSON.stringify([{ title: key, content: value }]);
const content = JSON.stringify([{ title: md5(question), content: answer }]);
// 数据
const data = {
txt_name: key,
txt_name: md5(question),
txt_content: content,
password: '',
v_id: '',
Expand All @@ -64,7 +72,7 @@ async function saveAnswer(key, value) {
// 请求成功
if (res.ok) {
const data = await res.json();
return data;
return <object>data;
}
} catch (error) {}
}
Expand Down
10 changes: 4 additions & 6 deletions src/component/ExamBtn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mainStore } from '../store';
import { examPause } from '../shared';
import { watchEffectRef } from '../utils/composition';
import { createElementNode, createTextNode } from '../utils/element';

Expand All @@ -11,18 +11,16 @@ function ExamBtn() {
undefined,
{
class: watchEffectRef(
mainStore.examPause,
() => `egg_exam_btn${mainStore.examPause.value ? ' manual' : ''}`
() => `egg_exam_btn${examPause.value ? ' manual' : ''}`
),
type: 'button',
onclick: () => {
mainStore.examPause.value = !mainStore.examPause.value;
examPause.value = !examPause.value;
},
},
createTextNode(
watchEffectRef(
mainStore.examPause,
() => `${mainStore.examPause.value ? '开启自动答题' : '关闭自动答题'}`
() => `${examPause.value ? '开启自动答题' : '关闭自动答题'}`
)
)
);
Expand Down
Loading

0 comments on commit bbf2148

Please sign in to comment.