From d6971509823705b8c7ac5de5159b8917b39dc45c Mon Sep 17 00:00:00 2001 From: kmmiio99o Date: Sun, 26 Apr 2026 11:28:06 +0200 Subject: [PATCH] Revert "feat: drop fixembed plugin and fix icon in main settings" This reverts commit 84f6592ecf94f550f43d8bda89eecd14f19142e4. --- src/core/plugins/fixembed/index.ts | 201 +++++++++++++++++++ src/core/plugins/index.ts | 1 + src/core/ui/settings/pages/General/index.tsx | 2 +- 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 src/core/plugins/fixembed/index.ts diff --git a/src/core/plugins/fixembed/index.ts b/src/core/plugins/fixembed/index.ts new file mode 100644 index 0000000..efda7f3 --- /dev/null +++ b/src/core/plugins/fixembed/index.ts @@ -0,0 +1,201 @@ +import { defineCorePlugin } from ".."; +import { findByProps } from "@metro"; +import { after } from "@lib/api/patcher"; +import { logger } from "@lib/utils/logger"; +import { settings } from "@lib/api/settings"; +import { React } from "@metro/common"; + +const { TableRowGroup, TableRow, TableSwitchRow, Stack } = findByProps( + "TableRowGroup", + "TableRow", + "TableSwitchRow", + "Stack", +); +const { ScrollView, Text } = require("react-native"); + +type FixEmbedSettings = { + twitter: boolean; + instagram: boolean; + tiktok: boolean; + reddit: boolean; +}; + +declare module "@lib/api/settings" { + interface Settings { + fixembed?: FixEmbedSettings; + } +} + +const MessageActions = findByProps("sendMessage"); +let unpatch: (() => void) | null = null; + +function transformLinks(content: string, config: FixEmbedSettings): string { + let result = content; + // Twitter/X: Replace domain, keep path + if (config.twitter) { + result = result.replace( + /https?:\/\/(?:www\.)?(twitter\.com|x\.com)(\/[^\s]+)/gi, + "https://fxtwitter.com$2", + ); + } + // Instagram: Replace domain, keep path + if (config.instagram) { + result = result.replace( + /https?:\/\/(?:www\.)?instagram\.com(\/[^\s]+)/gi, + "https://uuinstagram.com$1", + ); + } + // TikTok: Replace domain, keep path + if (config.tiktok) { + result = result.replace( + /https?:\/\/(?:www\.)?tiktok\.com(\/[^\s]+)/gi, + "https://tnktok.com$1", + ); + // TikTok short links (vm.tiktok.com) + result = result.replace( + /https?:\/\/vm\.tiktok\.com\/([A-Za-z0-9]+)\/?/gi, + "https://vm.tnktok.com/$1", + ); + } + // Reddit: Replace domain, keep path + if (config.reddit) { + result = result.replace( + /https?:\/\/(?:www\.)?reddit\.com(\/[^\s]+)/gi, + "https://rxddit.com$1", + ); + } + return result; +} + +export default defineCorePlugin({ + manifest: { + id: "bunny.fixembed", + version: "1.0.0", + type: "plugin", + spec: 3, + main: "", + display: { + name: "FixEmbed", + description: + "Improves social media embeds by using privacy-friendly alternative frontends.", + authors: [{ name: "ShiggyCord Team" }], + }, + }, + + SettingsComponent() { + const { useState, useEffect } = React; + const [config, setConfig] = useState({ + twitter: settings.fixembed?.twitter ?? true, + instagram: settings.fixembed?.instagram ?? true, + tiktok: settings.fixembed?.tiktok ?? true, + reddit: settings.fixembed?.reddit ?? true, + }); + + useEffect(() => { + settings.fixembed = config; + }, [config]); + + const updateConfig = (key: keyof FixEmbedSettings, value: boolean) => { + setConfig((prev) => ({ ...prev, [key]: value })); + }; + + // Prefer table-style rows (TableRowGroup / TableSwitchRow) and Stack layout similar to other core plugins. + const { + TableRowGroup: _TRG, + TableRow: _TR, + TableSwitchRow: _TSR, + Stack: _S, + } = findByProps("TableRowGroup", "TableRow", "TableSwitchRow", "Stack"); + + // Fallback if the table-style components are not available in the host environment + if (!_TRG || !_TSR || !_TR || !_S) { + return React.createElement( + ScrollView, + { style: { flex: 1, padding: 12 } }, + React.createElement( + Text, + null, + "FixEmbed UI unavailable (missing TableRow components).", + ), + ); + } + + // Use the resolved components + const TableRowGroup = _TRG; + const TableRow = _TR; + const TableSwitchRow = _TSR; + const Stack = _S; + + return React.createElement(ScrollView, { style: { flex: 1 } }, [ + React.createElement( + Stack, + { spacing: 8, style: { padding: 10 } }, + + React.createElement( + TableRowGroup, + { title: "Platforms" }, + React.createElement(TableSwitchRow, { + label: "Twitter/X", + value: config.twitter, + onValueChange: (v: boolean) => updateConfig("twitter", v), + }), + React.createElement(TableSwitchRow, { + label: "Instagram", + value: config.instagram, + onValueChange: (v: boolean) => updateConfig("instagram", v), + }), + React.createElement(TableSwitchRow, { + label: "TikTok", + value: config.tiktok, + onValueChange: (v: boolean) => updateConfig("tiktok", v), + }), + React.createElement(TableSwitchRow, { + label: "Reddit", + value: config.reddit, + onValueChange: (v: boolean) => updateConfig("reddit", v), + }), + ), + React.createElement( + TableRowGroup, + { title: "About" }, + React.createElement(TableRow, { + label: "Description", + subLabel: + "This plugin automatically converts social media links to privacy-friendly alternative frontends for better embeds.", + disabled: true, + }), + ), + ), + ]); + }, + + start() { + logger.log("FixEmbed: Starting plugin"); + settings.fixembed = settings.fixembed || { + twitter: true, + instagram: true, + tiktok: true, + reddit: true, + }; + + if (!unpatch) { + unpatch = after("sendMessage", MessageActions, (args) => { + const config = settings.fixembed!; + if (args[1]?.content) { + args[1].content = transformLinks(args[1].content, config); + args[1].nonce = args[1].nonce || Math.random().toString(36).slice(2); + } + }); + } + logger.log("FixEmbed: Patched outgoing messages"); + }, + + stop() { + logger.log("FixEmbed: Stopping plugin"); + if (unpatch) { + unpatch(); + unpatch = null; + } + logger.log("FixEmbed: Unpatched outgoing messages"); + }, +}); diff --git a/src/core/plugins/index.ts b/src/core/plugins/index.ts index e4d9c63..1545ea5 100644 --- a/src/core/plugins/index.ts +++ b/src/core/plugins/index.ts @@ -35,6 +35,7 @@ export const getCorePlugins = (): CorePluginRecord => ({ "bunny.badges": makeLazyPlugin(() => require("./badges")), "bunny.notrack": makeLazyPlugin(() => require("./notrack")), "bunny.messagefix": makeLazyPlugin(() => require("./messagefix")), + "bunny.fixembed": makeLazyPlugin(() => require("./fixembed")), }); /** diff --git a/src/core/ui/settings/pages/General/index.tsx b/src/core/ui/settings/pages/General/index.tsx index 357a3db..5708b98 100644 --- a/src/core/ui/settings/pages/General/index.tsx +++ b/src/core/ui/settings/pages/General/index.tsx @@ -200,7 +200,7 @@ export default function General() { } + icon={} value={settings.enableDiscordDeveloperSettings} onValueChange={(v: boolean) => { settings.enableDiscordDeveloperSettings = v;