Skip to content

Commit ef02c90

Browse files
committed
docs: update docs
1 parent 9f3260c commit ef02c90

File tree

11 files changed

+199
-156
lines changed

11 files changed

+199
-156
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v1.16.0
2+
- vite更新到5.0,antd更新到5.0
3+
- 添加禁用类型,可设置禁用 xhr 或 fetch
4+
- 添加插件拦截时机,可设置start end delay trigger override
5+
16
## v1.15.0
27
- 添加run at功能
38

public/_locales/en/messages.json

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"action_refresh": {
2727
"message": "Refresh Data"
2828
},
29+
"action_all_frames": {
30+
"message": "All frames"
31+
},
2932
"action_theme": {
3033
"message": "Switch Theme"
3134
},

public/_locales/zh_CN/messages.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"action_refresh": {
2727
"message": "刷新数据"
2828
},
29+
"action_all_frames": {
30+
"message": "所有frame生效"
31+
},
2932
"action_theme": {
3033
"message": "切换主题"
3134
},
@@ -116,7 +119,7 @@
116119
"message": "延时"
117120
},
118121
"run_at_trigger": {
119-
"message": "拦截"
122+
"message": "触发"
120123
},
121124
"run_at_override": {
122125
"message": "重写"

readme-zh_CN.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
>
3232
> 如果你是一个熟练度拉满,有着完善的代理环境大可不必使用,仅作为特定场合的补充
3333
>
34-
> 如果使用cdn版本,请保证能访问https://unpkg.com,首次加载会比较慢。或者直接使用local版本
34+
> 如果使用cdn版本,请保证能访问https://unpkg.com,首次加载会比较慢。如果加载不出来也可直接使用local版本
3535
3636
## 🎉 特点
3737

@@ -69,7 +69,9 @@
6969
## 状态栏
7070
- 【设置】:设置选项
7171
- 【工作空间】:切换工作空间
72-
- 【运行时机】:插件生效的时机,start-js注入即生效,end-DOMContentLoaded,delay-延时一定时间,trigger-当拦截到特定接口后触发
72+
- 【运行时机】:插件生效的时机,start-js注入即生效,end-DOMContentLoaded,delay-延时一定时间,trigger-当拦截到特定接口后触发,override-当window上的xhr或者fetch被重写时
73+
- 【禁用类型】:禁用请求类型:xhr 或者 fetch
74+
- 【存储占用率】:展示数据占用率
7375

7476
### config面板
7577

@@ -78,6 +80,7 @@
7880
|url|string|请求地址|
7981
|test|string|必选,匹配的请求地址,ant-path-matcher规则或字符串匹配,不允许写query参数|
8082
|type|xhr\|fetch|请求类型|
83+
|description|string|描述字段,做备注使用|
8184
|response|object\|array\|null\boolean\|number|响应数据|
8285
|responseText|string|响应数据|
8386
|delay|number|延迟的毫秒数|

readme.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ How to solve the above problems? If you can intercept and modify the data before
7272
## Status Bar
7373
- \[Setting\]: Setting
7474
- [Work Space]: Switch work space
75-
- [Run At]:four options can be choose. start (js injected will be work),end (DOMContentLoaded),delay (delay some times),trigger (match a url)
75+
- [Run At]: four options can be choose. start (js injected will be work),end (DOMContentLoaded),delay (delay some times),trigger (match a url),override (window.XMLHttpRequest or window.fetch was override)
76+
- \[Ban Type\]: Ban type, xhr or fetch
77+
- \[Quota\]: Percent of quota
7678

7779

7880
### Config Panel
@@ -82,6 +84,7 @@ How to solve the above problems? If you can intercept and modify the data before
8284
|url|string|request url|
8385
|test|string|required, match request url, ant-path-matcher rule or string match, cannot set query|
8486
|type|xhr\|fetch|request type|
87+
|description|string|note|
8588
|response|object\|array\|null\boolean\|number||
8689
|responseText|string||
8790
|delay|number||

src/App.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@
9898
padding: 0 4px;
9999
background-color: #007acc;
100100
color: white;
101-
cursor: pointer;
102101
&-item {
103102
padding: 0 4px;
104103
&:hover {
105104
background-color: #1f89d1;
105+
cursor: pointer;
106106
}
107107
}
108108
}

src/App.tsx

+30-31
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Quota, { getPercent } from './components/Quota'
2020
import { runCode } from './tools/runCode'
2121
import { loader } from "@monaco-editor/react";
2222
import { sendRequestLog } from './tools/sendRequest'
23-
import { ActiveGroupId, BootLogKey, DarkFieldKey, HiddenFieldsFieldKey, ActiveIdFieldKey, RulesFieldKey, SelectedRowFieldKeys, UpdateMsgKey, WatchFilterKey, ConfigInfoFieldKey, PopupMsgKey } from './tools/constants'
23+
import { ActiveGroupId, HiddenFieldsFieldKey, ActiveIdFieldKey, RulesFieldKey, SelectedRowFieldKeys, UpdateMsgKey, WatchFilterKey, ConfigInfoFieldKey, PopupMsgKey } from './tools/constants'
2424
import useTranslate from './hooks/useTranslate'
2525
import getStorage from './tools/getStorage'
2626
import { ConfigProvider, theme } from 'antd'
@@ -74,6 +74,8 @@ export interface ConfigInfoType {
7474
action: string
7575
banType: BanType
7676
bootLog: boolean
77+
allFrames: boolean
78+
dark: boolean
7779
}
7880

7981
const defaultConfigInfo: ConfigInfoType = {
@@ -84,22 +86,22 @@ const defaultConfigInfo: ConfigInfoType = {
8486
runAtTrigger: '**',
8587
action: 'close',
8688
banType: 'none',
87-
bootLog: false,
89+
bootLog: true,
90+
allFrames: false,
91+
dark: isDarkTheme,
8892
}
8993

9094
export default function App() {
91-
const [dark, setDark] = useStorage(DarkFieldKey, isDarkTheme)
95+
const [configInfo, setConfigInfo] = useStorage<ConfigInfoType>(ConfigInfoFieldKey, defaultConfigInfo)
9296
const [activeGroupId, setActiveGroupId] = useStorage(ActiveGroupId, 'default')
9397
const [watchFilter, setWatchFilter] = useStorage(WatchFilterKey, '')
94-
const [configInfo, setConfigInfo] = useStorage<ConfigInfoType>(ConfigInfoFieldKey, defaultConfigInfo)
9598
const [rules, setRules] = useStorage<MatchRule[]>(RulesFieldKey, [])
9699
const [selectedRowKeys, setSelectedRowKeys] = useStorage(SelectedRowFieldKeys, [])
97100
const [loading, setLoading] = useState(false)
98101
const [activeId, setActiveId] = useStorage<string>(ActiveIdFieldKey, null)
99102
const [invalid, setInvalid] = useState(false)
100103
const [visible, setVisible] = useState(false)
101104
const [hiddenFields, setHiddenFields] = useStorage<string[]>(HiddenFieldsFieldKey, [])
102-
const [bootLog, setBootLog] = useStorage(BootLogKey, true)
103105
const [percent, setPercent] = useState(0)
104106
const originRef = useRef('')
105107
const editorRef = useRef()
@@ -120,11 +122,9 @@ export default function App() {
120122
[ConfigInfoFieldKey]: setConfigInfo,
121123
[RulesFieldKey]: setRules,
122124
[SelectedRowFieldKeys]: setSelectedRowKeys,
123-
[DarkFieldKey]: setDark,
124125
[ActiveIdFieldKey]: setActiveId,
125126
[HiddenFieldsFieldKey]: setHiddenFields,
126127
[WatchFilterKey]: setWatchFilter,
127-
[BootLogKey]: setBootLog,
128128
[ActiveGroupId]: setActiveGroupId,
129129
}
130130

@@ -427,8 +427,6 @@ export default function App() {
427427
[]
428428
)
429429

430-
// 数据改变后通知background,并保存chrome.storage
431-
432430
useEffect(
433431
() => {
434432
if (!__DEV__) {
@@ -438,6 +436,15 @@ export default function App() {
438436
payload: configInfo,
439437
})
440438
}
439+
440+
const html = document.querySelector('html')
441+
const cls = 'theme--dark'
442+
if (configInfo.dark && !html.classList.contains(cls)) {
443+
html.classList.add(cls)
444+
} else {
445+
html.classList.remove(cls)
446+
document.head.querySelector('link[dark]')?.remove()
447+
}
441448
},
442449
[configInfo]
443450
)
@@ -453,20 +460,6 @@ export default function App() {
453460
},
454461
[workspaceRules]
455462
)
456-
useEffect(
457-
() => {
458-
const html = document.querySelector('html')
459-
const cls = 'theme--dark'
460-
if (dark && !html.classList.contains(cls)) {
461-
html.classList.add(cls)
462-
} else {
463-
html.classList.remove(cls)
464-
document.head.querySelector('link[dark]')?.remove()
465-
}
466-
},
467-
[dark]
468-
)
469-
470463
useEffect(
471464
() => {
472465
getPercent(sizeof(rules)).then(setPercent)
@@ -476,7 +469,7 @@ export default function App() {
476469

477470
return (
478471
<ConfigProvider theme={{
479-
algorithm: dark ? theme.darkAlgorithm : undefined,
472+
algorithm: configInfo.dark ? theme.darkAlgorithm : undefined,
480473
components: {
481474
Table: {
482475
headerBorderRadius: 0,
@@ -676,19 +669,21 @@ export default function App() {
676669
<>
677670
<Divider orientation='left' plain>
678671
<Button size='small' type='primary' onClick={() => {
679-
setDark(false)
680-
setBootLog(true)
681-
setConfigInfo(info => ({ ...info, fakedLog: true }))
672+
setConfigInfo(info => ({ ...info, fakedLog: true, bootLog: true, dark: false, allFrames: false }))
682673
}}>{t('action_reset')}</Button>
683674
</Divider>
684675
<Space size={'large'}>
676+
<div style={{ display: 'flex' }}>
677+
<span style={{ marginRight: 8 }}>{t('action_all_frames')}</span>
678+
<Switch checked={configInfo.allFrames} onClick={() => setConfigInfo(info => ({ ...info, allFrames: !info.allFrames }))}></Switch>
679+
</div>
685680
<div style={{ display: 'flex' }}>
686681
<span style={{ marginRight: 8 }}>{t('action_theme')}</span>
687-
<Switch checked={dark} onClick={() => setDark(dark => !dark)}></Switch>
682+
<Switch checked={configInfo.dark} onClick={() => setConfigInfo(info => ({ ...info, dark: !info.dark }))}></Switch>
688683
</div>
689684
<div style={{ display: 'flex' }}>
690685
<span style={{ marginRight: 8 }}>{t('action_boot_log')}</span>
691-
<Switch checked={bootLog} onClick={() => setBootLog(bootLog => !bootLog)}></Switch>
686+
<Switch checked={configInfo.bootLog} onClick={() => setConfigInfo(info => ({ ...info, bootLog: !info.bootLog }))}></Switch>
692687
</div>
693688
<div style={{ display: 'flex' }}>
694689
<span style={{ marginRight: 8 }}>{t('action_faked_log')}</span>
@@ -729,7 +724,11 @@ export default function App() {
729724
<Popover trigger={['click']} placement='top' showArrow={false} content={(
730725
<>
731726
<Segmented value={configInfo.runAt} onChange={(runAt: string) => {
732-
setConfigInfo(info => ({ ...info, runAt }))
727+
setConfigInfo(info => ({
728+
...info,
729+
runAt,
730+
action: (runAt === 'override' && info.action === 'close') ? 'intercept' : info.action,
731+
}))
733732
}} options={[
734733
{
735734
label: t('run_at_start'),
@@ -806,7 +805,7 @@ export default function App() {
806805
editable && (
807806
<div className='app__editor'>
808807
<MainEditor
809-
isDark={dark}
808+
isDark={configInfo.dark}
810809
ref={editorRef}
811810
index={activeIndex}
812811
rule={rules[activeIndex]}

src/background/index.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ chrome.tabs.onUpdated.addListener(update)
2929
// 接收popup传来的信息,并转发给content.js
3030
chrome.runtime.onMessage.addListener((msg: CustomEventProps) => {
3131
// 过滤非本插件的消息
32-
if (msg.from !== PopupMsgKey) return;
32+
if (msg.from !== PopupMsgKey) {
33+
return
34+
}
3335

3436
if (msg.type === 'rules') {
3537
__rules = msg.payload || []
@@ -180,6 +182,11 @@ function responseStartedWatch(details: chrome.webRequest.WebResponseCacheDetails
180182

181183
const urlObj = new URL(details.url)
182184

185+
if (details.method.toLowerCase() === 'options') {
186+
__result.delete(details.requestId)
187+
return
188+
}
189+
183190
chrome.storage.local.get([RulesFieldKey, ActiveGroupId], (result) => {
184191
chrome.storage.local.set({
185192
[RulesFieldKey]: [
@@ -222,6 +229,12 @@ function beforeRequestIntercept(details: chrome.webRequest.WebRequestBodyDetails
222229
}
223230

224231
function beforeRequestWatch(details: chrome.webRequest.WebRequestBodyDetails, url: string) {
232+
233+
// 过滤请求
234+
if (['OPTIONS', 'CONNEST', 'TRACE', 'HEAD'].includes(details.method)) {
235+
return
236+
}
237+
225238
if (! details.requestBody) {
226239
details.requestBody = { formData: {} }
227240
}

0 commit comments

Comments
 (0)