Skip to content

Commit f18a36e

Browse files
author
lucifer
committed
feat: first commit
1 parent 354480d commit f18a36e

12 files changed

+492
-137
lines changed

‎README.md

+18-56
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,30 @@
1-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
1+
## 刷题小助手
22

3-
## Available Scripts
3+
功能介绍:
44

5-
In the project directory, you can run:
5+
- [刷题效率低?或许你就差这么一个插件](https://lucifer.ren/blog/2020/06/06/algo-chrome-extension/)
66

7-
### `yarn start`
7+
## 开发
88

9-
Runs the app in the development mode.<br />
10-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
9+
目录结构:
1110

12-
The page will reload if you make edits.<br />
13-
You will also see any lint errors in the console.
11+
|-public 插件的 mainfest,html 等静态资源
12+
|-src 源代码
13+
|---db 所有的题目信息, 标签信息, 公司信息
14+
|---App.js 主逻辑都在这里
1415

15-
### `yarn test`
16+
## 构建
1617

17-
Launches the test runner in the interactive watch mode.<br />
18-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
18+
- npm run build
19+
- 然后将 build 文件夹的内容添加到扩展中即可,具体方式见上面的`功能介绍`
1920

20-
### `yarn build`
21+
> 以后每次执行 npm run build, 插件会自动刷新,无需手动加载。
2122
22-
Builds the app for production to the `build` folder.<br />
23-
It correctly bundles React in production mode and optimizes the build for the best performance.
23+
## 计划
2424

25-
The build is minified and the filenames include the hashes.<br />
26-
Your app is ready to be deployed!
25+
- [ ] 完善题目,优先级比较高的是 91 的这些题目,按照现有的两个题目的标准进行完善。
26+
- [ ] 标签完善。目前很多标签是没有对应的讲解的,比如递归,队列等。
2727

28-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
28+
## 参考
2929

30-
### `yarn eject`
31-
32-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33-
34-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35-
36-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37-
38-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39-
40-
## Learn More
41-
42-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43-
44-
To learn React, check out the [React documentation](https://reactjs.org/).
45-
46-
### Code Splitting
47-
48-
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49-
50-
### Analyzing the Bundle Size
51-
52-
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53-
54-
### Making a Progressive Web App
55-
56-
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57-
58-
### Advanced Configuration
59-
60-
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61-
62-
### Deployment
63-
64-
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65-
66-
### `yarn build` fails to minify
67-
68-
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
30+
- [chrome 扩展开发官方文档](https://developer.chrome.com/extensions)

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@testing-library/jest-dom": "^4.2.4",
77
"@testing-library/react": "^9.3.2",
88
"@testing-library/user-event": "^7.1.2",
9+
"antd": "^4.3.1",
910
"react": "^16.13.1",
1011
"react-dom": "^16.13.1",
1112
"react-scripts": "3.4.1"

‎public/logo.png

7.06 KB
Loading

‎public/manifest.json

+15-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
{
2-
"short_name": "React App",
3-
"name": "Create React App Sample",
4-
"icons": [
5-
{
6-
"src": "favicon.ico",
7-
"sizes": "64x64 32x32 24x24 16x16",
8-
"type": "image/x-icon"
9-
},
10-
{
11-
"src": "logo192.png",
12-
"type": "image/png",
13-
"sizes": "192x192"
14-
},
15-
{
16-
"src": "logo512.png",
17-
"type": "image/png",
18-
"sizes": "512x512"
19-
}
20-
],
21-
"start_url": ".",
22-
"display": "standalone",
23-
"theme_color": "#000000",
24-
"background_color": "#ffffff"
2+
"manifest_version": 2,
3+
4+
"name": "leetcode cheatsheet",
5+
"description": "刷题小助手,made by 力扣加加",
6+
"version": "0.0.1",
7+
8+
"browser_action": {
9+
"default_popup": "index.html",
10+
"default_title": "力扣加加"
11+
},
12+
"icons": {
13+
"128": "logo.png"
14+
},
15+
"permissions": ["tabs"],
16+
"content_security_policy": "script-src 'self' 'sha256-9HcBuUP35aPkU0991A4mASdsuifTkUlifJ7elThz6Ow=' 'sha256-0Jo/EYaXS11i7poc/P9fGcq/o6P0djny2JW6WivTVVw='; object-src 'self'"
2517
}

‎src/App.css

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
1-
.App {
2-
text-align: center;
1+
.container {
2+
color: #000;
3+
font-size: 15px;
4+
padding: 10px;
5+
width: 400px;
36
}
4-
5-
.App-logo {
6-
height: 40vmin;
7-
pointer-events: none;
8-
}
9-
10-
@media (prefers-reduced-motion: no-preference) {
11-
.App-logo {
12-
animation: App-logo-spin infinite 20s linear;
13-
}
7+
.row {
8+
margin: 0 0 10px 0;
149
}
1510

16-
.App-header {
17-
background-color: #282c34;
18-
min-height: 100vh;
19-
display: flex;
20-
flex-direction: column;
21-
align-items: center;
22-
justify-content: center;
23-
font-size: calc(10px + 2vmin);
24-
color: white;
11+
.label {
12+
line-height: 20px;
13+
color: rgba(0, 0, 0, 0.84);
2514
}
2615

27-
.App-link {
28-
color: #61dafb;
16+
.code-block {
17+
margin: 10px 0;
2918
}
3019

31-
@keyframes App-logo-spin {
32-
from {
33-
transform: rotate(0deg);
34-
}
35-
to {
36-
transform: rotate(360deg);
37-
}
20+
.language {
21+
display: inline-block;
22+
width: 80px;
3823
}

‎src/App.js

+134-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,140 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
1+
import React, { useState } from "react";
2+
import { Tabs, Tag, Button, Table, Empty, message } from "antd";
3+
4+
import { copy } from "./utils";
5+
import db from "./db/db";
6+
7+
import "antd/dist/antd.css";
8+
import "./App.css";
9+
10+
const { TabPane } = Tabs;
11+
const { problems, tags: tagMapper } = db;
12+
const dataSource = Object.values(problems);
13+
14+
function TagOrLink({ link, text }) {
15+
return link !== null ? (
16+
<a className="link" href={link} rel="noopener noreferrer" target="_blank">
17+
<Button type="link">{text}</Button>
18+
</a>
19+
) : (
20+
<Tag color="orange">{text}</Tag>
21+
);
22+
}
23+
24+
const columns = [
25+
{
26+
title: "题目",
27+
dataIndex: "name",
28+
key: "name",
29+
render: (name, row) => (
30+
<a
31+
className="link"
32+
href={`https://leetcode-cn.com/problems/${name}/`}
33+
rel="noopener noreferrer"
34+
target="_blank"
35+
>
36+
<Button type="link">
37+
{row.id}.{name}
38+
</Button>
39+
</a>
40+
),
41+
},
42+
{
43+
title: "标签",
44+
dataIndex: "tags",
45+
key: "tags",
46+
render: (tags) => (
47+
<>
48+
{tags.map((tag) => {
49+
return <TagOrLink text={tagMapper[tag.id].text} link={tag.link} />;
50+
})}
51+
</>
52+
),
53+
},
54+
];
455

556
function App() {
57+
// eslint-disable-next-line
58+
chrome.tabs &&
59+
// eslint-disable-next-line
60+
chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => {
61+
const currentUrl = tabs[0].url;
62+
const match = currentUrl.match(/problems\/(.+?)\//);
63+
const problemId = match && match[1];
64+
setProblemId(problemId);
65+
setShow(!!problems[problemId]);
66+
});
67+
68+
const [problemId, setProblemId] = useState("");
69+
const [show, setShow] = useState(false);
70+
671
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.js</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
72+
<div className="container">
73+
{show ? (
74+
<Tabs defaultActiveKey="0">
75+
<TabPane tab="前置知识" key="0">
76+
{problems[problemId].pre.map(({ link, text }) => (
77+
<TagOrLink text={text} link={link} />
78+
))}
79+
</TabPane>
80+
<TabPane tab="关键点" key="1">
81+
{problems[problemId].keyPoints.map(({ link, text }) => (
82+
<TagOrLink text={text} link={link} />
83+
))}
84+
</TabPane>
85+
<TabPane tab="题解" key="2">
86+
<a
87+
className="link nav"
88+
href={problems[problemId].solution}
89+
rel="noopener noreferrer"
90+
target="_blank"
91+
>
92+
<Button type="link">前往题解</Button>
93+
</a>
94+
</TabPane>
95+
<TabPane tab="代码" key="3">
96+
<div className="code-block">
97+
{problems[problemId].code.map((c) => (
98+
<div className="row" style={{ marginTop: "10px" }}>
99+
<span className="language language-js">{c.language}</span>
100+
<Button
101+
type="primary"
102+
size="small"
103+
onClick={() =>
104+
copy(c.text, () => {
105+
message.success("复制成功~");
106+
})
107+
}
108+
>
109+
复制
110+
</Button>
111+
</div>
112+
))}
113+
</div>
114+
</TabPane>
115+
<TabPane tab="公司" key="4">
116+
{problems[problemId].company.map((c) => c.name).join(",")}
117+
</TabPane>
118+
<TabPane
119+
tab="可视化调试(敬请期待)"
120+
key="5"
121+
disabled={true}
122+
></TabPane>
123+
</Tabs>
124+
) : (
125+
<div>
126+
<Empty description="正在撰写题解...">
127+
<div className="row" style={{ marginTop: "20px" }}>
128+
所有已收录的题目
129+
</div>
130+
<Table
131+
pagination={{ hideOnSinglePage: true }}
132+
dataSource={dataSource}
133+
columns={columns}
134+
/>
135+
</Empty>
136+
</div>
137+
)}
22138
</div>
23139
);
24140
}

0 commit comments

Comments
 (0)