diff --git a/packages/app-extension/src/background/index.ts b/packages/app-extension/src/background/index.ts index cdcc6df0da..d1a92fcb0a 100644 --- a/packages/app-extension/src/background/index.ts +++ b/packages/app-extension/src/background/index.ts @@ -1,5 +1,44 @@ import { start } from "@coral-xyz/background"; +import { supportedDomains, urlPatterns } from "../dns-redirects/constants"; +import { redirect } from "../dns-redirects/helpers/tabHelper"; + start({ isMobile: false, }); + +/** + * Resolves domain names in the form of URLs. + */ +chrome.webNavigation.onBeforeNavigate.addListener( + async (details) => { + await redirect(details.url); + }, + { + url: supportedDomains.map((domain) => { + return { urlMatches: `^[^:]+://[^/]+.${domain}/.*$` }; + }), + } +); + +/** + * Resolves domain names in the form of browser searches via Google, Bing, etc. + * DuckDuckGo has a unique search pattern and must be queried separately. + */ +chrome.webNavigation.onBeforeNavigate.addListener( + async (details) => { + const domainUrl = new URL(details.url).searchParams.get("q"); + if (domainUrl && domainUrl.indexOf(" ") < 0) await redirect(domainUrl); + }, + { + url: supportedDomains.flatMap((param) => + urlPatterns.map((pattern) => { + return { + urlMatches: pattern.includes("duckduckgo") + ? `${pattern}\\.${param}$` + : `${pattern}\\.${param}&.*$`, + }; + }) + ), + } +); diff --git a/packages/app-extension/src/components/Unlocked/Settings/Preferences/WebDomainResolver/CustomIpfsGateway.tsx b/packages/app-extension/src/components/Unlocked/Settings/Preferences/WebDomainResolver/CustomIpfsGateway.tsx new file mode 100644 index 0000000000..203b958d2e --- /dev/null +++ b/packages/app-extension/src/components/Unlocked/Settings/Preferences/WebDomainResolver/CustomIpfsGateway.tsx @@ -0,0 +1,60 @@ +import { useState } from "react"; +import { UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE } from "@coral-xyz/common"; +import { useTranslation } from "@coral-xyz/i18n"; +import { InputListItem, Inputs, PrimaryButton } from "@coral-xyz/react-common"; +import { useBackgroundClient } from "@coral-xyz/recoil"; + +import { setIPFSGateway } from "../../../../../dns-redirects/helpers"; + +export function PreferencesCustomIpfsGateway() { + const background = useBackgroundClient(); + const { t } = useTranslation(); + + const [gatewayUrl, setGatewayUrl] = useState(""); + const changeIpfsGateway = async () => { + try { + background + .request({ + method: UI_RPC_METHOD_SETTINGS_DOMAIN_CONTENT_IPFS_GATEWAY_UPDATE, + params: [gatewayUrl], + }) + .catch(console.error); + + await setIPFSGateway(gatewayUrl); + } catch (err) { + console.error(err); + } + }; + + return ( +