From c67b87ea4d87b0681fab9b262e12e75034d21a3c Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Thu, 12 Jun 2025 02:11:44 -0400 Subject: [PATCH] Update ThemesTab --- src/components/ThemeSettings/ThemesTab.tsx | 83 ++++++++++++++++++- src/equicordplugins/clientSideBlock/index.tsx | 4 +- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/components/ThemeSettings/ThemesTab.tsx b/src/components/ThemeSettings/ThemesTab.tsx index dc9dc7f4..c65a3030 100644 --- a/src/components/ThemeSettings/ThemesTab.tsx +++ b/src/components/ThemeSettings/ThemesTab.tsx @@ -20,6 +20,7 @@ import "./themesStyles.css"; import { Settings, useSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; +import { ErrorCard } from "@components/ErrorCard"; import { Flex } from "@components/Flex"; import { CogWheel, DeleteIcon, FolderIcon, PaintbrushIcon, PencilIcon, PluginIcon, PlusIcon, RestartIcon } from "@components/Icons"; import { Link } from "@components/Link"; @@ -27,16 +28,19 @@ import { openPluginModal } from "@components/PluginSettings/PluginModal"; import { AddonCard } from "@components/VencordSettings/AddonCard"; import { QuickAction, QuickActionCard } from "@components/VencordSettings/quickActions"; import { SettingsTab, wrapTab } from "@components/VencordSettings/shared"; +import { CspBlockedUrls, useCspErrors } from "@utils/cspViolations"; import { openInviteModal } from "@utils/discord"; +import { Margins } from "@utils/margins"; +import { classes } from "@utils/misc"; import { openModal } from "@utils/modal"; -import { showItemInFolder } from "@utils/native"; -import { useAwaiter } from "@utils/react"; +import { relaunch, showItemInFolder } from "@utils/native"; +import { useAwaiter, useForceUpdater } from "@utils/react"; import type { ThemeHeader } from "@utils/themes"; import { getThemeInfo, stripBOM, type UserThemeHeader } from "@utils/themes/bd"; import { usercssParse } from "@utils/themes/usercss"; import { getStylusWebStoreUrl } from "@utils/web"; import { findLazy } from "@webpack"; -import { Button, Card, Forms, React, showToast, TabBar, TextInput, Tooltip, useEffect, useMemo, useRef, useState } from "@webpack/common"; +import { Alerts, Button, Card, Forms, React, showToast, TabBar, TextInput, Tooltip, useEffect, useMemo, useRef, useState } from "@webpack/common"; import type { ComponentType, Ref, SyntheticEvent } from "react"; import type { UserstyleHeader } from "usercss-meta"; @@ -497,12 +501,85 @@ function ThemesTab() { + {currentTab === ThemeTab.LOCAL && } {currentTab === ThemeTab.ONLINE && } ); } +export function CspErrorCard() { + if (IS_WEB) return null; + + const errors = useCspErrors(); + const forceUpdate = useForceUpdater(); + + if (!errors.length) return null; + + const isImgurHtmlDomain = (url: string) => url.startsWith("https://imgur.com/"); + + const allowUrl = async (url: string) => { + const { origin: baseUrl, hostname } = new URL(url); + + const result = await VencordNative.csp.requestAddOverride(baseUrl, ["connect-src", "img-src", "style-src", "font-src"], "Vencord Themes"); + if (result !== "ok") return; + + CspBlockedUrls.forEach(url => { + if (new URL(url).hostname === hostname) { + CspBlockedUrls.delete(url); + } + }); + + forceUpdate(); + + Alerts.show({ + title: "Restart Required", + body: "A restart is required to apply this change", + confirmText: "Restart now", + cancelText: "Later!", + onConfirm: relaunch + }); + }; + + const hasImgurHtmlDomain = errors.some(isImgurHtmlDomain); + + return ( + + Blocked Resources + Some images, styles, or fonts were blocked because they come from disallowed domains. + It is highly recommended to move them to GitHub or Imgur. But you may also allow domains if you fully trust them. + + After allowing a domain, you have to fully close (from tray / task manager) and restart {IS_DISCORD_DESKTOP ? "Discord" : IS_EQUIBOP ? "Equibop" : "Vesktop"} to apply the change. + + + Blocked URLs + + {errors.map((url, i) => ( + + {i !== 0 && } + + {url} + allowUrl(url)} disabled={isImgurHtmlDomain(url)}> + Allow + + + + ))} + + + {hasImgurHtmlDomain && ( + <> + + + Imgur links should be direct links in the form of https://i.imgur.com/... + + To obtain a direct link, right-click the image and select "Copy image address". + > + )} + + ); +} + function UserscriptThemesTab() { return ( diff --git a/src/equicordplugins/clientSideBlock/index.tsx b/src/equicordplugins/clientSideBlock/index.tsx index cf6415bc..8a6a49f5 100644 --- a/src/equicordplugins/clientSideBlock/index.tsx +++ b/src/equicordplugins/clientSideBlock/index.tsx @@ -209,11 +209,11 @@ export default definePlugin({ find: "NOW_PLAYING_CARD_HOVERED,", replacement: [ { - match: /(\{party:)(\i)(.*?\}=\i)/, + match: /(let\{party:)(\i)(.*?\}=\i)/, replace: "$1eq_$2$3,$2=$self.partyFilterIgnoredUsers(eq_$2)", }, { - match: /\{party:(\i).*,\i=\i\(\)\(\i,\i\);/, + match: /let\{party:(\i).*,\i=\i\(\)\(\i,\i\);/, replace: "$&if($self.shoudBeNull($1)){return null;}" } ]
https://i.imgur.com/...