Skip to content

Commit 7e4029f

Browse files
committed
feat: 添加功能开关配置
Squashed commit of the following: commit eb9a396ee29d2bf2ab9cc55228ad8c716e10e3c9 Author: XYShaoKang <[email protected]> Date: Mon Jan 30 17:38:04 2023 +0800 添加全部禁用和启用的快捷方式 commit e0866c30d69d9142c06415031d68b1fad657465f Author: XYShaoKang <[email protected]> Date: Mon Jan 30 15:12:29 2023 +0800 配置题单页开关 commit b8c01e5dbf3a56b8c6ef61df47c209bd64c43ec7 Author: XYShaoKang <[email protected]> Date: Mon Jan 30 14:48:39 2023 +0800 配置题库页开关 commit 3c1025f6583f1a287e7d9fbd89d8a812ee2012e2 Author: XYShaoKang <[email protected]> Date: Mon Jan 30 05:19:38 2023 +0800 修复答题页 commit ddc090d856ca9ad26f16f17c0fa498f7f589b624 Author: XYShaoKang <[email protected]> Date: Mon Jan 30 04:11:27 2023 +0800 统一处理所有页面 commit cdd50a6b21b2f07b4afd538074f4c8586171ce21 Author: XYShaoKang <[email protected]> Date: Mon Jan 30 03:47:06 2023 +0800 配置竞赛排名页开关 commit b7d4526ab38fb11e39e269fca211946e23edd380 Author: XYShaoKang <[email protected]> Date: Sun Jan 29 15:43:23 2023 +0800 配置答题页开关 commit 93a8eba806a12cae7636b5db354912a05fb15b25 Author: XYShaoKang <[email protected]> Date: Sun Jan 29 15:01:46 2023 +0800 配置首页黑名单开关 commit a5f5c76422345c66e5f458a0a1711d14e4c9807e Author: XYShaoKang <[email protected]> Date: Sun Jan 29 07:33:21 2023 +0800 添加 options
1 parent f2d8551 commit 7e4029f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1594
-1184
lines changed

config/common.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const CopyPlugin = require('copy-webpack-plugin')
99
const common = {
1010
entry: {
1111
popup: path.join(__dirname, '../src/popup/index.tsx'),
12+
options: path.join(__dirname, '../src/options/index.tsx'),
1213
content: path.join(__dirname, '../src/content/index.tsx'),
1314
'content-load': path.join(__dirname, '../src/content/load.ts'),
1415
background: path.join(__dirname, '../src/background/index.ts'),
@@ -45,6 +46,12 @@ const common = {
4546
],
4647
},
4748
plugins: [
49+
new HtmlWebpackPlugin({
50+
template: path.join(__dirname, '../public', 'options.html'),
51+
chunks: ['options'],
52+
filename: 'options.html',
53+
publicPath: '/',
54+
}),
4855
new HtmlWebpackPlugin({
4956
template: path.join(__dirname, '../public', 'popup.html'),
5057
chunks: ['popup'],

config/development.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const development = env => ({
1414
publicPath: 'http://localhost:9100/',
1515
},
1616
entry: {
17+
options: [
18+
'webpack/hot/dev-server.js',
19+
'webpack-dev-server/client/index.js?hot=true&protocol=ws&hostname=localhost&port=9100',
20+
path.join(__dirname, '../src/options/index.tsx'),
21+
],
1722
popup: [
1823
'webpack/hot/dev-server.js',
1924
'webpack-dev-server/client/index.js?hot=true&protocol=ws&hostname=localhost&port=9100',

public/manifest-dev.json

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
"48": "icons/icon-48.png",
1010
"128": "icons/icon-128.png"
1111
},
12-
"content_security_policy": {
13-
"extension_pages": "default-src 'self' http://localhost:9100; script-src 'self' http://localhost:9100; script-src-elem 'self' http://localhost:9100; style-src 'self' 'unsafe-inline'; connect-src 'self' ws://localhost:9100 http://localhost:9100 https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com https://leetcode.cn https://lccn.lbao.site"
14-
},
15-
"permissions": [
16-
"scripting"
17-
],
1812
"web_accessible_resources": [
1913
{
2014
"resources": [
@@ -30,14 +24,6 @@
3024
]
3125
}
3226
],
33-
"host_permissions": [
34-
"https://leetcode-cn.com/*",
35-
"https://leetcode.cn/*",
36-
"http://localhost:9100/*",
37-
"https://leetcode-rating-predictor.herokuapp.com/*",
38-
"https://leetcode-predictor.herokuapp.com/*",
39-
"https://lccn.lbao.site/*"
40-
],
4127
"content_scripts": [
4228
{
4329
"matches": [
@@ -52,6 +38,25 @@
5238
"background": {
5339
"service_worker": "background.bundle.js"
5440
},
41+
"options_page": "options.html",
42+
"action": {
43+
"default_popup": "popup.html"
44+
},
45+
"content_security_policy": {
46+
"extension_pages": "default-src 'self' http://localhost:9100; script-src 'self' http://localhost:9100; script-src-elem 'self' http://localhost:9100; style-src 'self' 'unsafe-inline'; connect-src 'self' ws://localhost:9100 http://localhost:9100 https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com https://leetcode.cn https://lccn.lbao.site"
47+
},
48+
"permissions": [
49+
"scripting",
50+
"storage"
51+
],
52+
"host_permissions": [
53+
"https://leetcode-cn.com/*",
54+
"https://leetcode.cn/*",
55+
"http://localhost:9100/*",
56+
"https://leetcode-rating-predictor.herokuapp.com/*",
57+
"https://leetcode-predictor.herokuapp.com/*",
58+
"https://lccn.lbao.site/*"
59+
],
5560
"externally_connectable": {
5661
"matches": [
5762
"https://leetcode-cn.com/*",

public/manifest.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
"48": "icons/icon-48.png",
1010
"128": "icons/icon-128.png"
1111
},
12-
"content_security_policy": {
13-
"extension_pages": "default-src 'self'; script-src 'self'; script-src-elem 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com https://leetcode.cn https://lccn.lbao.site"
14-
},
15-
"permissions": [],
1612
"web_accessible_resources": [
1713
{
1814
"resources": [
@@ -26,13 +22,6 @@
2622
]
2723
}
2824
],
29-
"host_permissions": [
30-
"https://leetcode-cn.com/*",
31-
"https://leetcode.cn/*",
32-
"https://leetcode-rating-predictor.herokuapp.com/*",
33-
"https://leetcode-predictor.herokuapp.com/*",
34-
"https://lccn.lbao.site/*"
35-
],
3625
"content_scripts": [
3726
{
3827
"matches": [
@@ -47,6 +36,23 @@
4736
"background": {
4837
"service_worker": "background.bundle.js"
4938
},
39+
"options_page": "options.html",
40+
"action": {
41+
"default_popup": "popup.html"
42+
},
43+
"content_security_policy": {
44+
"extension_pages": "default-src 'self'; script-src 'self'; script-src-elem 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://leetcode-rating-predictor.herokuapp.com https://leetcode-predictor.herokuapp.com https://leetcode-cn.com https://leetcode.cn https://lccn.lbao.site"
45+
},
46+
"permissions": [
47+
"storage"
48+
],
49+
"host_permissions": [
50+
"https://leetcode-cn.com/*",
51+
"https://leetcode.cn/*",
52+
"https://leetcode-rating-predictor.herokuapp.com/*",
53+
"https://leetcode-predictor.herokuapp.com/*",
54+
"https://lccn.lbao.site/*"
55+
],
5056
"externally_connectable": {
5157
"matches": [
5258
"https://leetcode-cn.com/*",

public/options.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Refined LeetCode</title>
7+
</head>
8+
<body>
9+
<noscript>You need to enable JavaScript to run this app.</noscript>
10+
<div id="root"></div>
11+
</body>
12+
</html>

public/popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
6-
<title>LeetCode Extension</title>
6+
<title>Refined LeetCode</title>
77
</head>
88
<body>
99
<noscript>You need to enable JavaScript to run this app.</noscript>

src/content/App.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { FC } from 'react'
2+
import { withRoot } from './hoc'
3+
4+
import Ranking from './pages/ranking/App'
5+
import Home from './pages/home/App'
6+
import Timer from './pages/problems/App'
7+
import ShortcutKeyOption from './pages/problems/ShortcutKeyOption'
8+
import Problemset from './pages/problemset/App'
9+
import ProblemList from './pages/problem-list/App'
10+
11+
const App: FC = () => {
12+
return (
13+
<>
14+
<Ranking />
15+
<Home />
16+
<Timer />
17+
<ShortcutKeyOption />
18+
<Problemset />
19+
<ProblemList />
20+
</>
21+
)
22+
}
23+
24+
export default withRoot(App)

src/content/app/store.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { apiSlice } from '@/pages/ranking/rankSlice'
1111
import postsReducer from '@/pages/home/postsSlice'
1212
import blockUsersReducer from '@/pages/home/blockUsersSlice'
1313
import globalDataReducer, { fetchGlobalData } from '@/pages/global/globalSlice'
14-
import optionReducer from '@/pages/global/optionSlice'
14+
import optionsReducer from '@/pages/global/optionsSlice'
1515
import favoritesReducer from '@/pages/problem-list/favoriteSlice'
1616
import questionsReducer from '@/pages/problemset/questionsSlice'
1717

@@ -36,6 +36,7 @@ const config = {
3636
'blockUsers/unSetBlockUser',
3737
'blockUsers/toggleBlockUser',
3838
'global/fetchGlobalData/fulfilled',
39+
'options/toggleContestProblemShortcutKeyOption',
3940
],
4041
}
4142

@@ -82,12 +83,12 @@ const persistedQuestionsReducer = persistReducer(
8283
},
8384
questionsReducer
8485
)
85-
const persistedOptionReducer = persistReducer(
86+
const persistedOptionsReducer = persistReducer(
8687
{
8788
key: 'refined-leetcode-option',
8889
storage: localforage,
8990
},
90-
optionReducer
91+
optionsReducer
9192
)
9293

9394
const store = configureStore({
@@ -96,7 +97,7 @@ const store = configureStore({
9697
posts: postsReducer,
9798
blockUsers: persistedUsersReducer,
9899
global: globalDataReducer,
99-
option: persistedOptionReducer,
100+
options: persistedOptionsReducer,
100101
favorites: favoritesReducer,
101102
questions: persistedQuestionsReducer,
102103
},
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { ChangeEventHandler, FC } from 'react'
2+
import { css } from 'styled-components/macro'
3+
import {
4+
CheckBoxCheckedIcon,
5+
CheckBoxIndeterminateIcon,
6+
CheckBoxUncheckedIcon,
7+
} from './icons'
8+
9+
interface CheckboxProps {
10+
checked?: boolean
11+
indeterminate?: boolean
12+
onChange?: ChangeEventHandler<HTMLInputElement>
13+
size?: number
14+
color?: string
15+
}
16+
17+
const Checkbox: FC<CheckboxProps> = ({
18+
checked,
19+
indeterminate,
20+
onChange,
21+
size,
22+
color,
23+
}) => {
24+
const Icon = indeterminate
25+
? CheckBoxIndeterminateIcon
26+
: checked
27+
? CheckBoxCheckedIcon
28+
: CheckBoxUncheckedIcon
29+
const chandleChange: ChangeEventHandler<HTMLInputElement> = e => {
30+
onChange?.(e)
31+
}
32+
return (
33+
<span
34+
css={css`
35+
cursor: pointer;
36+
position: relative;
37+
display: flex;
38+
align-items: center;
39+
`}
40+
>
41+
<input
42+
type="checkbox"
43+
checked={checked}
44+
onChange={chandleChange}
45+
css={css`
46+
opacity: 0;
47+
position: absolute;
48+
margin: 0;
49+
padding: 0;
50+
left: 0;
51+
top: 0;
52+
height: 100%;
53+
width: 100%;
54+
cursor: pointer;
55+
`}
56+
/>
57+
<Icon width={size} height={size} color={color} />
58+
</span>
59+
)
60+
}
61+
62+
export default Checkbox

src/content/components/Switch.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useRef, useState } from 'react'
2+
3+
interface SwitchProps {
4+
enable?: boolean
5+
height?: number
6+
width?: number
7+
onToggle?: () => void
8+
}
9+
10+
const Switch: React.FC<SwitchProps> = ({
11+
enable: enableProp,
12+
height,
13+
width,
14+
onToggle,
15+
}) => {
16+
const { current: isControlled } = useRef(enableProp !== undefined)
17+
const [state, setState] = useState<boolean>()
18+
const handleToggle = () => {
19+
setState(!state)
20+
if (onToggle) onToggle()
21+
}
22+
if (height === undefined && width === undefined) height = 24
23+
const enable = isControlled ? enableProp : state
24+
return (
25+
<svg
26+
viewBox="0 0 24 24"
27+
style={{ width, height, cursor: 'pointer' }}
28+
onClick={handleToggle}
29+
>
30+
{enable ? (
31+
<path
32+
d="M17 7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h10c2.76 0 5-2.24 5-5s-2.24-5-5-5zm0 8c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z"
33+
fill="currentColor"
34+
color="rgb(144, 202, 249)"
35+
/>
36+
) : (
37+
<path
38+
d="M17 7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h10c2.76 0 5-2.24 5-5s-2.24-5-5-5zM7 15c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z"
39+
fill="currentColor"
40+
/>
41+
)}
42+
</svg>
43+
)
44+
}
45+
46+
export default Switch

0 commit comments

Comments
 (0)