Skip to content

Commit 9c49acd

Browse files
committed
Update README.zh.md
1 parent ebfc784 commit 9c49acd

File tree

1 file changed

+177
-30
lines changed

1 file changed

+177
-30
lines changed

README.zh.md

Lines changed: 177 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,20 @@ const {session} = remote
7474

7575
```javascript
7676
import { remote } from "electron"
77-
const { session } = remote,
78-
$leetcode = new $Leetcode(),
79-
leetcodeUserStatus = null
77+
const { session } = remote
78+
,$leetcode = new $Leetcode()
8079

8180
;function someFn(questionSlug){
8281
session.defaultSession.webRequest.onBeforeSendHeaders({ urls: ['https://leetcode-cn.com/problems/*'] }, (details, callback) => {
8382
details.requestHeaders['Referer'] = `https://leetcode-cn.com/problems/${questionSlug}/submissions/`
8483
callback({ cancel: false, requestHeaders: details.requestHeaders })
8584
})
8685
$leetcode.getUserStatus().then((response)=>{
87-
if(response.status == 200){
86+
if(response.status == 200)
8887
const { userStatus } = response.data.data
89-
// leetcodeUserStatus = userStatus
90-
}
9188
else
9289
console.log(response)
90+
//...
9391
})
9492
}
9593
```
@@ -102,40 +100,189 @@ const { session } = remote,
102100

103101
下文表格中提到的 Cookie 项,是指用户在登录力扣官方网站生成的 **LEETCODE_SESSION****x-csrftoken** 项,获取方法:使用浏览器登录成功后,打开开发人员工具中的网络一项,寻找成功状态的 graphql 请求,在请求信息中可以找到这两项的值。
104102

105-
### 用户状态
103+
> 接口中标注 `必须使用Cookie` 时,即必须携带上述两项 Cookie 进行网络请求才能获取到数据;接口中标注 `可以不使用Cookie` 时,即携带上述两项 Cookie 进行网络请求才能获取到完整数据(表项中带有 * 的需要携带 Cookie 才能正常获取);无标注即为普通的网络请求,不需要携带 Cookie 也能正常获取到完整数据。
104+
105+
### 用户状态[^必须使用Cookie]
106106

107107
```javascript
108108
const $leetcode = new $Leetcode()
109-
;$leetcode.getUserStatus() // with cookie [LEETCODE_SESSION,x-csrftoken]
109+
110+
;$leetcode.getUserStatus().then((response)=>{
111+
if(response.status == 200)
112+
const { commonNojPermissionTypes, jobsMyCompany, userStatus } = response.data.data
113+
else
114+
console.log(response)
115+
//...
116+
}) // must with cookie [LEETCODE_SESSION,x-csrftoken]
110117
```
111118

112119
请求数据项:
113120

114-
| Item | Value |
115-
| :--------: | :-----------------------------------------: |
116-
| Type | POST |
117-
| Parameters | NULL |
118-
| URL | `https://leetcode-cn.com/graphql` |
119-
| Require | Cookie Item [LEETCODE_SESSION, x-csrftoken] |
121+
| Item | Value |
122+
| :--------: | :-------------------------------------------- |
123+
| Type | `POST` |
124+
| Parameters | `NULL` |
125+
| URL | `https://leetcode-cn.com/graphql` |
126+
| Require | `Cookie Item [LEETCODE_SESSION, x-csrftoken]` |
120127

121128
获取到的数据项:
122129

123-
| Key | Value | Describe |
124-
| :-------------------------: | :-----: | :--------------- |
125-
| commonNojPermissionTypes | Array | 未知 |
126-
| jobsMyCompany | Object | 用户公司 |
127-
| userStatus | Object | 用户状态 |
128-
| userStatus.avatar | String | 用户头像 |
129-
| userStatus.isAdmin | Boolean | 是否是管理员 |
130+
| Key | Value | Describe |
131+
| :-------------------------- | :-----: | :--------------- |
132+
| commonNojPermissionTypes | Array | 未知 |
133+
| jobsMyCompany | Object | 用户公司 |
134+
| userStatus | Object | 用户状态 |
135+
| userStatus.avatar | String | 用户头像 |
136+
| userStatus.isAdmin | Boolean | 是否是管理员 |
130137
| userStatus.isPhoneVerified | Boolean | 是否通过手机验证 |
131-
| userStatus.isPremium | Boolean | 未知 |
132-
| userStatus.isSignedIn | Boolean | 是否登录 |
133-
| userStatus.isSuperuser | Boolean | 是否是VIP |
134-
| userStatus.isTranslator | Boolean | 是否是翻译 |
135-
| userStatus.isVerified | Boolean | 是否通过身份验证 |
138+
| userStatus.isPremium | Boolean | 未知 |
139+
| userStatus.isSignedIn | Boolean | 是否登录 |
140+
| userStatus.isSuperuser | Boolean | 是否是VIP |
141+
| userStatus.isTranslator | Boolean | 是否是翻译 |
142+
| userStatus.isVerified | Boolean | 是否通过身份验证 |
136143
| userStatus.premiumExpiredAt | Number | 未知 |
137-
| userStatus.realName | String | 用户昵称 |
138-
| userStatus.useTranslation | Boolean | 是否使用翻译 |
139-
| userStatus.userSlug | String | 用户标签 |
140-
| userStatus.username | String | 用户名 |
144+
| userStatus.realName | String | 用户昵称 |
145+
| userStatus.useTranslation | Boolean | 是否使用翻译 |
146+
| userStatus.userSlug | String | 用户标签 |
147+
| userStatus.username | String | 用户名 |
148+
149+
### 题目集合[^可以不使用Cookie]
150+
151+
```javascript
152+
const $leetcode = new $Leetcode()
153+
,categorySlug = "" //defalut
154+
,skip = 0 //defalut
155+
,limit = 25 //defalut
156+
157+
;$leetcode.getQuestionSet(categorySlug, skip, limit).then((response)=>{
158+
if(response.status == 200)
159+
const { problemsetQuestionList } = response.data.data
160+
else
161+
console.log(response)
162+
//...
163+
}) // with cookie [LEETCODE_SESSION,x-csrftoken] or not
164+
```
165+
166+
请求数据项:
167+
168+
| Item | Value |
169+
| :--------: | :----------------------------------------------------- |
170+
| Type | `POST` |
171+
| Parameters | `categorySlug`, `skip`, `limit` |
172+
| URL | `https://leetcode-cn.com/graphql` |
173+
| Require | `NULL` / `Cookie Item [LEETCODE_SESSION, x-csrftoken]` |
174+
175+
参数项:
176+
177+
- `categorySlug`,分类名,获取的题目集合将只含有此分类,默认分类为空字符串。
178+
- `skip`,跳过数,分页相关,获取数量从头部减去 skip 条,默认为 0 条。
179+
- `limit`,数据数量,分页相关,获取数据的数量,默认为 25 条。
180+
181+
获取到的数据项:
182+
183+
| Key | Value | Describe |
184+
| :----------------------------------------------------------- | :-----: | :----------------------------------- |
185+
| problemsetQuestionList | Array | 题目集合对象 |
186+
| problemsetQuestionList.hasMore | Boolean | 是否有更多题目 |
187+
| problemsetQuestionList.questions | Array | 题目集合 |
188+
| problemsetQuestionList.questions.acRate | Number | 题目通过率 |
189+
| problemsetQuestionList.questions.difficulty | String | 题目难度 |
190+
| problemsetQuestionList.questions.extra | Object | 题目额外信息 |
191+
| problemsetQuestionList.questions.extra.companyTagNum | Number | 公司数量 |
192+
| problemsetQuestionList.questions.extra.hasVideoSolution | Boolean | 该题是否有解法视频 |
193+
| problemsetQuestionList.questions.extra.topCompanyTags | Array | 相关公司集合 |
194+
| problemsetQuestionList.questions.extra.topCompanyTags.imgUrl | String | 相关公司头像 |
195+
| problemsetQuestionList.questions.extra.topCompanyTags.slug | String | 相关公司标题 |
196+
| problemsetQuestionList.questions.freqBar | Boolean | 未知 |
197+
| problemsetQuestionList.questions.frontendQuestionId | String | 题目的前端ID |
198+
| *problemsetQuestionList.questions.isFavor | Boolean | 题目是否被收藏,需要用户登录 |
199+
| problemsetQuestionList.questions.paidOnly | Boolean | 题目是否付费 |
200+
| problemsetQuestionList.questions.solutionNum | Number | 题目已知解法数量 |
201+
| *problemsetQuestionList.questions.status | String | 题目通过状态,需要用户登录,默认NULL |
202+
| problemsetQuestionList.questions.title | String | 题目的题名 |
203+
| problemsetQuestionList.questions.titleCn | String | 题目的题名(中文) |
204+
| problemsetQuestionList.questions.titleSlug | String | 题目的标题 |
205+
| problemsetQuestionList.questions.topicTags | Array | 题目相关话题集合 |
206+
| problemsetQuestionList.questions.topicTags.id | String | 话题ID |
207+
| problemsetQuestionList.questions.topicTags.name | String | 话题名称 |
208+
| problemsetQuestionList.questions.topicTags.nameTranslated | String | 话题名称(中文) |
209+
| problemsetQuestionList.questions.topicTags.slug | String | 话题标题 |
210+
| problemsetQuestionList.total | Number | 题目总数 |
211+
212+
### 题目详情[^可以不使用Cookie]
213+
214+
```javascript
215+
const $leetcode = new $Leetcode()
216+
,questionSlug = "two-sum"
217+
218+
;$leetcode.getQuestion(questionSlug).then((res)=>{
219+
if(res.status == 200)
220+
const { question } = res.data.data
221+
}) // with cookie [LEETCODE_SESSION,x-csrftoken] or not
222+
```
223+
224+
请求数据项:
225+
226+
| Item | Value |
227+
| :--------: | :----------------------------------------------------- |
228+
| Type | `POST` |
229+
| Parameters | `questionSlug` |
230+
| URL | `https://leetcode-cn.com/graphql` |
231+
| Require | `NULL` / `Cookie Item [LEETCODE_SESSION, x-csrftoken]` |
232+
233+
参数项:
234+
235+
- `questionSlug`,题目标题,必须是 `question.titleSlug` 的可选值。
236+
237+
获取到的数据项:
141238

239+
| Key | Value | Describe |
240+
| :-------------------------------- | :------------: | :-------------------------------- |
241+
| question | Object | 题目对象 |
242+
| question.book | Object? | 题目书籍 |
243+
| question.boundTopicId | Object | 题目相关话题数量 |
244+
| question.categoryTitle | String | 题目分类名 |
245+
| question.codeSnippets | String | 题目代码对象 |
246+
| question.codeSnippets.code | String | 题目代码内容(初始值) |
247+
| question.codeSnippets.lang | String | 题目代码语言 |
248+
| question.codeSnippets.langSlug | String | 题目代码语言标题 |
249+
| question.companyTagStats | String? | 未知,题目相关公司? |
250+
| question.content | String | 题目内容 |
251+
| question.contributors | Array[Object?] | 未知,题目贡献者? |
252+
| question.dailyRecordStatus | String | 题目每日状态记录 |
253+
| question.difficulty | String | 题目难度 |
254+
| question.dislikes | Number | 题目踩数量 |
255+
| question.editorType | String | 未知,题目编辑器风格? |
256+
| question.enableRunCode | Boolean | 是否可以运行代码 |
257+
| question.envInfo | String | 题目警告信息 |
258+
| question.exampleTestcases | String | 题目样例 |
259+
| question.hints | Array[String] | 题目提示 |
260+
| question.isDailyQuestion | Boolean | 是否是每日一题 |
261+
| *question.isLiked | String? | 题目是否点赞 |
262+
| question.isPaidOnly | Boolean | 题目是否付费 |
263+
| *question.isSubscribed | Boolean | 是否订阅题目 |
264+
| question.judgeType | String | 未知,题目判定类型? |
265+
| question.judgerAvailable | Boolean | 未知,判定是否可用? |
266+
| question.langToValidPlayground | String | 题目可用的语言 |
267+
| question.likes | Number | 题目赞数量 |
268+
| question.metaData | String | 题目预设信息 |
269+
| question.mysqlSchemas | Array[Object?] | 未知,题目数据库信息? |
270+
| question.questionFrontendId | String | 题目前端ID |
271+
| question.questionId | String | 题目ID |
272+
| question.sampleTestCase | String | 题目一般测试用例 |
273+
| question.similarQuestions | String | 相似题目对象(JSON.stringfy) |
274+
| question.solution | Object | 题目解法对象 |
275+
| question.solution.canSeeDetail | Boolean | 未知,题目解法细节是否可见? |
276+
| question.solution.id | String | 题目解法ID |
277+
| question.stats | String | 题目通过状态(总体)(JSON.stringfy) |
278+
| *question.status | String | 题目通过状态,需要用户登录 |
279+
| question.style | String | 未知,题目风格? |
280+
| question.title | String | 题目题名 |
281+
| question.titleSlug | String | 题目标题 |
282+
| question.topicTags | Array | 题目话题标签 |
283+
| question.topicTags.name | String | 题目话题标签名 |
284+
| question.topicTags.slug | String | 题目话题标签标题 |
285+
| question.topicTags.translatedName | String | 题目话题标签名(中文) |
286+
| question.translatedContent | String | 题目内容(中文) |
287+
| question.translatedTitle | String | 题目题名(中文) |
288+
| question.ugcQuestionId | String | 未知,题目UGCID? |

0 commit comments

Comments
 (0)