diff --git a/src/background/index.ts b/src/background/index.ts index 8d43daf..04a701e 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -55,7 +55,6 @@ async function buildCookieValue(accountName: string): Promise { return cookies .map((cookie) => `${cookie.name}=${cookie.value}`) - .concat(`__account__=${accountName}`) .join('; ') } @@ -83,7 +82,7 @@ async function buildAddRules(): Promise { ], }, condition: { - regexFilter: `${rule.urlPattern}|__account__=${rule.account}`, + regexFilter: `${rule.urlPattern}`, resourceTypes: RESOURCE_TYPES, }, }) @@ -188,7 +187,7 @@ function interceptRequests() { const autoSwitchRules = await ruleService.getAll() for (const rule of autoSwitchRules) { - const urlPattern = `${rule.urlPattern}|__account__=${rule.account}` + const urlPattern = `${rule.urlPattern}` if (new RegExp(urlPattern).test(details.url)) { const cookieValue = await buildCookieValue(rule.account) if (cookieValue) { diff --git a/src/content/index.ts b/src/content/index.ts index 02e0e7f..fa11dff 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -10,7 +10,6 @@ import { import './index.css' // Script that will be injected in the main page import { createElement } from './createElement' -import injectedScript from './injected?script&module' import { ACCOUNT_ITEM_CLASS, ACCOUNT_REMOVE_CLASS, ADD_ACCOUNT_BUTTON_ID, createAccountItem, createAddAccountLink, createDivider } from './ui' async function addSwitchUserMenu(logoutForm: HTMLFormElement) { @@ -84,13 +83,6 @@ async function switchAccount(account: string) { } } -function injectScript() { - const script = document.createElement('script') - script.src = browser.runtime.getURL(injectedScript) - script.type = 'module' - document.head.prepend(script) -} - function ready(fn: () => void) { if (document.readyState !== 'loading') { fn() @@ -126,7 +118,6 @@ function watchDom() { } async function init() { - injectScript() ready(watchDom) document.addEventListener('click', (event) => { diff --git a/src/content/injected.ts b/src/content/injected.ts deleted file mode 100644 index 83c2761..0000000 --- a/src/content/injected.ts +++ /dev/null @@ -1,68 +0,0 @@ -type FetchFn = typeof fetch -type FetchInput = Parameters[0] - -const ACCOUNT_PARAM = '__account__' - -class PatchedResponse extends Response { - constructor(private readonly response: Response) { - super(response.body, response) - } - - get url() { - const url = new URL(this.response.url, window.location.origin) - url.searchParams.delete(ACCOUNT_PARAM) - return url.href - } -} - -function patchUrl(oldUrl: string | URL) { - const account = document.querySelector('meta[name="user-login"]')?.content - if (!account) { - return oldUrl - } - - const newUrl = new URL(oldUrl, window.location.origin) - newUrl.searchParams.append(ACCOUNT_PARAM, account) - - return newUrl -} - -function patchRequestInfo(input: RequestInfo | URL) { - if (input instanceof Request) { - return input - } - - return patchUrl(input) -} - -function patchRequest() { - const OriginalRequest = window.Request - class PatchedRequest extends OriginalRequest { - constructor(input: RequestInfo | URL, init?: RequestInit) { - super(patchRequestInfo(input), init) - } - } - - window.Request = PatchedRequest -} - -function patchFetch() { - const originalFetch = window.fetch - const patchedFetch: FetchFn = async (input, options) => { - try { - const res = await originalFetch(patchRequestInfo(input), options) - return new PatchedResponse(res) - } catch (err) { - console.warn('Failed to fetch:', err) - throw err - } - } - window.fetch = patchedFetch -} - -function init() { - patchRequest() - patchFetch() -} - -init()