Skip to content

Commit be728df

Browse files
committed
Update README.md
1 parent 3cdeab2 commit be728df

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ HttpRequest api for leetcode(zh-cn).
1717
## 免责声明
1818

1919
**本项目仅供学习交流参考,在任意情况下均不得用于任何商业用途。如若违反声明,后果自负,本人不承担任何责任。**
20+
2021
**This project is for study and exchange only, and under no circumstances shall it be used for any commercial purposes. If you violate the statement, you are responsible for the consequences, and I do not assume any responsibility.**
2122

2223
## 项目总览
2324

2425
本项目提供的是 **力扣** 官方网站的 **WebApi** 集合,提出的 Api 均已试验成功。
26+
2527
This project provides the **WebApi** collection of **Leetcode**, and the proposed Api has been successfully tested.
2628

2729
本项目仅包含一个入口 Javascript 文件,将本文档中提出的 WebApi 全部封装到 $Leetcode 类中。
30+
2831
This project contains only an entry Javascript file that wraps all of the Webapis proposed in this document into the $Leetcode class.
2932

3033
所以,想使用 Leetcode-Api,你只需:
34+
3135
So, to use Leetcode-API, you just need to:
3236

3337
```javascript
@@ -37,11 +41,13 @@ const variable = new $Leetcode()
3741
```
3842

3943
然后通过上例中的 variable 使用 Leetcode-Api 中的函数方法。
44+
4045
Then use the function in Leetcode-API through the variable in the above example.
4146

4247
## 接口相关
4348

4449
力扣 官网使用了 [**GraphQL**](https://graphql.org/) 技术来获取数据,即 **按需分配数据** 的模式。同时,全部网络请求需要附着 Cookie 访问,部分网络请求需要确认 **Referer** 是否属于力扣域名之下。请使用这些 WebApi 之前制定好相关解决方案。
50+
4551
Leetcode uses [**GraphQL**](https://graphql.org/) technology to obtain data, that is, the mode of **on-demand data distribution**. At the same time, all network requests need to be attached with Cookie access, and some network requests need to confirm whether the **Referer** belongs to Leetcode domain name. Develop a solution before using these WebApis.
4652

4753
### 部分解决方案
@@ -60,12 +66,15 @@ In traditional HTML5 projects, such as:
6066
```
6167

6268
这种项目中,由于伪造 Referer 带来的不安全和危险,一般不会允许用户通过 Javascript 脚本去修改 HttpRequest 的表头中的几项,也就是 RequestHeader 中的几项,其中就包含有 Referer 项。
69+
6370
In such projects, due to the safety and risk of forgery of the Referer, it is generally not allowed to modify the items in the HttpRequest header, i.e. the items in the RequestHeader, which contain the Referer item.
6471

6572
而在 Vue 的脚手架中可以使用 Webpack 相关的 **DevProxy** 项设置相关的请求表头,从而起到伪造 Referer 以获取数据的效果。
73+
6674
In Vue-Cil project, the Webpack **DevProxy** item can be used to set up the relevant request headers, thus creating the effect of faking the Referer for data.
6775

6876
这样的例子在互联网上有许多,本人不在这里一一赘述,正好最近在写一个新的 [**Electron**](https://www.electronjs.org/) 项目,用到了伪造 Referer 的功能,在这里可以举例一番。
77+
6978
There are many such examples on the Internet, and I won't repeat them all here. Recently, I was writing a new [**Electron**](https://www.electronjs.org/) project, which used the function of forging Referer. Here I can give some examples.
7079

7180
```javascript
@@ -82,6 +91,7 @@ const {session} = remote
8291
```
8392

8493
在给出的实例化的对象中,所有的函数方法都会返回 [**axios**](https://www.axios-http.cn/) 对象。所以,你可以从函数的 **then** 回调中获取数据,例如:
94+
8595
In the given instantiated object, all function methods return [**axios**](https://www.axios-http.cn/) objects. So, you can get data from the function's **then** callback, for example:
8696

8797
```javascript
@@ -107,23 +117,28 @@ const { session } = remote,
107117
```
108118

109119
相关的文档请移步相关技术或者自行查询。
120+
110121
For related documents, refer to related technologies or query them by yourself.
111122

112123
## 接口详情
113124

114125
所有接口在文档更新时均已通过测试。
126+
115127
All interfaces were tested when the document was updated.
116128

117129
下文表格中提到的 Cookie 项,是指用户在登录力扣官方网站生成的 **LEETCODE_SESSION****x-csrftoken** 项,获取方法:使用浏览器登录成功后,打开开发人员工具中的网络一项,寻找成功状态的 graphql 请求,在请求信息中可以找到这两项的值。
130+
118131
The Cookie items mentioned in the table below refer to the **LEETCODE_SESSION** and **x-csrftoken** items generated when users log in to the official website of Leetcode. The method of obtaining them is as follows: After logging in successfully using the browser, open the network item in the developer tool and look for the graphQL request in the successful state. The values of the two items can be found in the request information.
119132

120133
### 用户状态
121134

122135
```javascript
123-
$Leetcode.getUserStatus() // with cookie [LEETCODE_SESSION,x-csrftoken]
136+
const $leetcode = new $Leetcode()
137+
;$leetcode.getUserStatus() // with cookie [LEETCODE_SESSION,x-csrftoken]
124138
```
125139

126140
请求数据项:
141+
127142
Requested data item:
128143

129144
| Item | Value |
@@ -134,6 +149,7 @@ Requested data item:
134149
| Require | Cookie Item [LEETCODE_SESSION, x-csrftoken] |
135150

136151
获取到的数据项:
152+
137153
Obtained data items:
138154

139155
| Key | Value | Describe |
@@ -144,12 +160,12 @@ Obtained data items:
144160
| userStatus.avatar | String | 用户头像 User avatar |
145161
| userStatus.isAdmin | Boolean | 是否是管理员 User admin status |
146162
| userStatus.isPhoneVerified | Boolean | 是否通过手机验证 User phone verify status |
147-
| userStatus.isPremium | Boolean | User premium status |
163+
| userStatus.isPremium | Boolean | 未知 Unknow |
148164
| userStatus.isSignedIn | Boolean | 是否登录 User sign status |
149165
| userStatus.isSuperuser | Boolean | 是否是VIP User vip role status |
150166
| userStatus.isTranslator | Boolean | 是否是翻译 User translator role status |
151167
| userStatus.isVerified | Boolean | 是否通过身份验证 User verify status |
152-
| userStatus.premiumExpiredAt | Number | User premium expiration |
168+
| userStatus.premiumExpiredAt | Number | 未知 Unknow |
153169
| userStatus.realName | String | 用户昵称 User detail name |
154170
| userStatus.useTranslation | Boolean | 是否使用翻译 User translation status |
155171
| userStatus.userSlug | String | 用户标签 User using slug |

0 commit comments

Comments
 (0)