Skip to content

Commit

Permalink
fix: fixed override mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hans000 committed Aug 27, 2024
1 parent 18e87d5 commit bc5280a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion public/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"message": "快速填充当前域名"
},
"action_add": {
"message": "关闭"
"message": "添加"
},
"action_remove": {
"message": "删除"
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const fields = [
'body',
'response',
'responseText',
'chunks',
'chunkInterval',
'chunkTemplate',
'chunks',
]

const isDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches
Expand Down
64 changes: 34 additions & 30 deletions src/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,42 @@ window.addEventListener(PageScriptEventName, (event) => {
} else if (value.runAt === 'trigger') {
updateData()
} else if (value.runAt === 'override') {
Object.defineProperty(window, 'fetch', {
set(value) {
window._fetch = value;
updateData()
handle(data.type, data.payload, {
NativeFetch: window._fetch,
NativeXhr: window._XMLHttpRequest,
})
},
get() {
if (window._fetch) {
return window._fetch
if (! window._fetch) {
Object.defineProperty(window, 'fetch', {
set(value) {
window._fetch = value;
updateData()
handle(data.type, data.payload, {
NativeFetch: window._fetch,
NativeXhr: window._XMLHttpRequest,
})
},
get() {
if (window._fetch) {
return window._fetch
}
return originFetch;
}
return originFetch;
}
});
Object.defineProperty(window, 'XMLHttpRequest', {
set(value) {
window._XMLHttpRequest = value;
updateData()
handle(data.type, data.payload, {
NativeFetch: window._fetch,
NativeXhr: window._XMLHttpRequest,
})
},
get() {
if (window._XMLHttpRequest) {
return window._XMLHttpRequest
});
}
if (! window._XMLHttpRequest) {
Object.defineProperty(window, 'XMLHttpRequest', {
set(value) {
window._XMLHttpRequest = value;
updateData()
handle(data.type, data.payload, {
NativeFetch: window._fetch,
NativeXhr: window._XMLHttpRequest,
})
},
get() {
if (window._XMLHttpRequest) {
return window._XMLHttpRequest
}
return originXhr;
}
return originXhr;
}
});
});
}
} else {
updateData()
handle(data.type, data.payload)
Expand Down

0 comments on commit bc5280a

Please sign in to comment.