Skip to content

Commit fbdeea8

Browse files
committed
Revert "feat: add proxy function"
This reverts commit 46c772c.
1 parent 6dea007 commit fbdeea8

File tree

10 files changed

+19
-75
lines changed

10 files changed

+19
-75
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build:local": "cross-env VITE_LOCAL=true node script.js && cross-env VITE_LOCAL=true npm run build:web && cross-env VITE_LOCAL=true npm run build:ts"
1111
},
1212
"dependencies": {
13+
"@ant-design/compatible": "^5.1.2",
1314
"@ant-design/icons": "^5.2.6",
1415
"@monaco-editor/react": "^4.4.6",
1516
"antd": "^5.12.1",

public/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"default_locale": "zh_CN",
2121
"content_security_policy" : "script-src 'self' 'unsafe-eval'; script-src-elem 'self' data: blob: https://unpkg.com; worker-src 'self' data: blob:; object-src 'self'",
2222
"browser_action": {
23-
"default_title": "Easy Interceptor by hans000 - v1.17.0",
23+
"default_title": "Easy Interceptor by hans000 - v1.16.0",
2424
"default_popup": "index.html",
2525
"default_icon": "images/128-gray.png"
2626
},

src/App.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ export default function App() {
164164
}
165165

166166
const update = (value: Record<FileType, string>, index: number) => {
167+
const configInfo = JSON.parse(value.setting)
168+
setConfigInfo(configInfo)
167169
setRules(rule => {
168170
const result = [...rule]
169171
const config = JSON.parse(value.config)
@@ -822,14 +824,7 @@ export default function App() {
822824
setFileName(fileName)
823825
}}
824826
onChange={(value, invalid) => {
825-
if (fileName === 'setting') {
826-
if (!invalid) {
827-
const configInfo = JSON.parse(value.setting)
828-
setConfigInfo(configInfo)
829-
}
830-
} else {
831-
update(value, activeIndex)
832-
}
827+
update(value, activeIndex)
833828
setInvalid(invalid)
834829
}} />
835830
</div>

src/background/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ActiveGroupId, BackgroundMsgKey, ConfigInfoFieldKey, PopupMsgKey, Rules
88
import { CustomEventProps, sendMessageToContent } from "../tools/message"
99
import updateIcon from "../tools/updateIcon"
1010
import { arrayBufferToString, createRunFunc, objectToHttpHeaders, randID, trimUrlParams } from "../tools"
11-
import { URL } from "url"
1211

1312
let __result = new Map<string, any>()
1413
let __rules: MatchRule[] = []
@@ -215,8 +214,6 @@ function responseStartedWatch(details: chrome.webRequest.WebResponseCacheDetails
215214
function beforeRequestIntercept(details: chrome.webRequest.WebRequestBodyDetails, url: string) {
216215
for (const rule of __rules) {
217216
if (rule.enable && matchPath(rule.test, url)) {
218-
// 处理重定向优先级
219-
// code面板 > rule.redirectUrl
220217
const fn = createRunFunc(rule.code, 'onRedirect')
221218
const redirectUrl = fn({
222219
...rule,

src/injected/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ const app = {
9696
configInfo: {} as ConfigInfoType,
9797
rules: [],
9898
intercept(fetcher?: FetcherType) {
99-
const { faked, fakedLog, banType, proxy } = app.configInfo
99+
const { faked, fakedLog, banType } = app.configInfo
100100
proxyRequest({
101101
...fetcher,
102102
faked,
103103
fakedLog,
104104
banType,
105-
proxy,
106105
onMatch(req) {
107106
if (app.configInfo.action === 'intercept') {
108107
return matching(app.rules, req)

src/injected/proxy/fetch.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The AGPL License (AGPL)
33
* Copyright (c) 2022 hans000
44
*/
5-
import { delayRun, tryToProxyUrl } from "../../tools";
5+
import { delayRun } from "../../tools";
66
import { log } from "../../tools/log";
77
import { parseUrl } from "../../tools";
88
import { Options, __global__ } from "./globalVar";
@@ -22,9 +22,8 @@ export function proxyFetch(options: Options) {
2222
const proxyFetch = new Proxy(__global__.NativeFetch, {
2323
async apply(target, thisArg, args) {
2424
const [input, init] = args
25-
const isRequest = input instanceof Request
26-
const req = isRequest ? input.clone() : new Request(input.toString(), init)
27-
const url = isRequest
25+
const req = input instanceof Request ? input.clone() : new Request(input.toString(), init)
26+
const url = input instanceof Request
2827
? parseUrl(input.url)
2928
: input instanceof URL
3029
? input
@@ -36,8 +35,6 @@ export function proxyFetch(options: Options) {
3635
params: [...url.searchParams.entries()],
3736
})
3837
const realFetch = __global__.PageFetch || target
39-
const proxyUrl = tryToProxyUrl(input, __global__.options.proxy)
40-
const proxyInput = isRequest ? new Request(proxyUrl, init) : proxyUrl
4138

4239
if (matchItem) {
4340
const loggable = options.faked && options.fakedLog
@@ -51,7 +48,7 @@ export function proxyFetch(options: Options) {
5148
}
5249
const realResponse = options.faked
5350
? new Response(new Blob(['null']))
54-
: await realFetch.call(thisArg, proxyInput, init)
51+
: await realFetch.call(thisArg, input, init)
5552
const response = await onFetchIntercept(matchItem)(realResponse)
5653

5754
return new Promise(resolve => {
@@ -71,11 +68,10 @@ export function proxyFetch(options: Options) {
7168
}, matchItem ? matchItem.delay : undefined)
7269
})
7370
}
74-
7571
if (__global__.PageFetch) {
76-
return __global__.PageFetch.call(thisArg, proxyInput, init)
72+
return __global__.PageFetch.call(thisArg, ...args)
7773
}
78-
return target.call(thisArg, proxyInput, init)
74+
return target.call(thisArg, ...args)
7975
},
8076
})
8177

@@ -104,4 +100,4 @@ export function unproxyFetch() {
104100
}
105101
})
106102
}
107-
}
103+
}

src/injected/proxy/globalVar.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The AGPL License (AGPL)
33
* Copyright (c) 2022 hans000
44
*/
5-
import { MatchRule, BanType, ConfigInfoType } from "../../App"
5+
import { MatchRule, BanType } from "../../App"
66

77
interface GlobalVar {
88
NativeXhr: typeof XMLHttpRequest | undefined
@@ -23,7 +23,6 @@ export interface Options {
2323
faked: boolean
2424
fakedLog: boolean
2525
banType?: BanType
26-
proxy?: ConfigInfoType['proxy']
2726
NativeFetch?: typeof fetch
2827
NativeXhr?: typeof XMLHttpRequest
2928
onMatch?: (reqestInfo: CustomRequestInfo) => MatchRule

src/injected/proxy/handle.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { MatchRule } from "../../App"
7-
import { createSymbol, delayRun, modifyXhrProto, modifyXhrProtoProps, toTitleCase, tryToProxyUrl } from "../../tools"
7+
import { createSymbol, delayRun, modifyXhrProto, modifyXhrProtoProps, toTitleCase } from "../../tools"
88
import { log } from "../../tools/log"
99
import { parseUrl, parseXML, stringifyHeaders } from "../../tools"
1010
import { HttpStatusCodes } from "./constants"
@@ -101,11 +101,10 @@ export function proxyXhrInstance(inst: ProxyXMLHttpRequest) {
101101
const originOpen = inst.open
102102
const originSend = inst.send
103103
inst.open = (method: string, url: string | URL, async?: boolean) => {
104-
const proxyUrl = tryToProxyUrl(url, __global__.options.proxy)
105104
inst._async = async
106-
inst._url = proxyUrl
105+
inst._url = url
107106
inst._method = method
108-
originOpen.call(inst, method, proxyUrl, async)
107+
originOpen.call(inst, method, url, async)
109108
}
110109
inst.send = (data) => {
111110
const delay = inst._matchItem ? inst._matchItem.delay : undefined
@@ -225,4 +224,4 @@ export function proxyFakeXhrInstance(inst: ProxyXMLHttpRequest, options: Options
225224
}
226225

227226
return inst
228-
}
227+
}

src/tools/JsonParse.ts

-13
This file was deleted.

src/tools/index.ts

+1-30
Original file line numberDiff line numberDiff line change
@@ -221,33 +221,4 @@ export function matchPath(pattern: string, path: string) {
221221

222222
export function toTitleCase(str = '') {
223223
return str.replace(/\b[a-z]/g, c => c.toUpperCase())
224-
}
225-
226-
export function tryToProxyUrl(url: string | URL, proxy: Record<string, string | {
227-
target: string
228-
rewrite?: string
229-
}> = {}) {
230-
const urlObj = url instanceof URL ? url : new URL(url)
231-
for (const [name, value] of Object.entries(proxy)) {
232-
try {
233-
const reg = new RegExp(name)
234-
if (reg.test(urlObj.pathname)) {
235-
if (typeof value === 'string') {
236-
urlObj.host = value
237-
return urlObj.toString()
238-
} else {
239-
if (value.target) {
240-
urlObj.host = value.target
241-
}
242-
if (value.rewrite) {
243-
urlObj.pathname = urlObj.pathname.replace(reg, '')
244-
}
245-
return urlObj.toString()
246-
}
247-
}
248-
} catch (error) {
249-
console.error(error)
250-
}
251-
}
252-
return url
253-
}
224+
}

0 commit comments

Comments
 (0)