chore: Update .gitignore and add .idea folder, update npm dependencies, and improve code logic for chat history and knowledge export/import
This commit is contained in:
@@ -1,31 +1,51 @@
|
||||
export const chromeRunTime = async function (domain: string) {
|
||||
if (typeof chrome !== "undefined" && chrome.runtime && chrome.runtime.id) {
|
||||
const url = new URL(domain)
|
||||
const domains = [url.hostname]
|
||||
const rules = [
|
||||
{
|
||||
id: 1,
|
||||
priority: 1,
|
||||
condition: {
|
||||
requestDomains: domains
|
||||
},
|
||||
action: {
|
||||
type: "modifyHeaders",
|
||||
requestHeaders: [
|
||||
{
|
||||
header: "Origin",
|
||||
operation: "set",
|
||||
value: `${url.protocol}//${url.hostname}`
|
||||
}
|
||||
]
|
||||
if (browser.runtime && browser.runtime.id) {
|
||||
if (import.meta.env.BROWSER === "chrome") {
|
||||
const url = new URL(domain)
|
||||
const domains = [url.hostname]
|
||||
const rules = [
|
||||
{
|
||||
id: 1,
|
||||
priority: 1,
|
||||
condition: {
|
||||
requestDomains: domains
|
||||
},
|
||||
action: {
|
||||
type: "modifyHeaders",
|
||||
requestHeaders: [
|
||||
{
|
||||
header: "Origin",
|
||||
operation: "set",
|
||||
value: `${url.protocol}//${url.hostname}`
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
await chrome.declarativeNetRequest.updateDynamicRules({
|
||||
removeRuleIds: rules.map((r) => r.id),
|
||||
// @ts-ignore
|
||||
addRules: rules
|
||||
})
|
||||
await browser.declarativeNetRequest.updateDynamicRules({
|
||||
removeRuleIds: rules.map((r) => r.id),
|
||||
// @ts-ignore
|
||||
addRules: rules
|
||||
})
|
||||
}
|
||||
|
||||
if (import.meta.env.BROWSER === "firefox") {
|
||||
const url = new URL(domain)
|
||||
const domains = [`*://${url.hostname}/*`]
|
||||
browser.webRequest.onBeforeSendHeaders.addListener(
|
||||
(details) => {
|
||||
for (let i = 0; i < details.requestHeaders.length; i++) {
|
||||
if (details.requestHeaders[i].name === "Origin") {
|
||||
details.requestHeaders[i].value =
|
||||
`${url.protocol}//${url.hostname}`
|
||||
}
|
||||
}
|
||||
return { requestHeaders: details.requestHeaders }
|
||||
},
|
||||
{ urls: domains },
|
||||
["blocking", "requestHeaders"]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user