Translate: Only add button in chat box

This commit is contained in:
V 2023-05-11 02:34:25 +02:00
parent 4d0a064425
commit 6e3cafce42
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905
2 changed files with 10 additions and 3 deletions

@ -37,9 +37,12 @@ export function TranslateIcon({ height = 24, width = 24, className }: { height?:
); );
} }
export function TranslateChatBarIcon() { export function TranslateChatBarIcon({ slateProps }: { slateProps: { type: { analyticsName: string; }; }; }) {
const { autoTranslate } = settings.use(["autoTranslate"]); const { autoTranslate } = settings.use(["autoTranslate"]);
if (slateProps.type.analyticsName !== "normal")
return null;
return ( return (
<Tooltip text="Open Translate Modal"> <Tooltip text="Open Translate Modal">
{({ onMouseEnter, onMouseLeave }) => ( {({ onMouseEnter, onMouseLeave }) => (

@ -45,7 +45,7 @@ export default definePlugin({
find: ".activeCommandOption", find: ".activeCommandOption",
replacement: { replacement: {
match: /(.)\.push.{1,30}disabled:(\i),.{1,20}\},"gift"\)\)/, match: /(.)\.push.{1,30}disabled:(\i),.{1,20}\},"gift"\)\)/,
replace: "$&;try{$2||$1.push($self.chatBarIcon())}catch{}", replace: "$&;try{$2||$1.push($self.chatBarIcon(arguments[0]))}catch{}",
} }
}, },
], ],
@ -82,5 +82,9 @@ export default definePlugin({
removeAccessory("vc-translation"); removeAccessory("vc-translation");
}, },
chatBarIcon: ErrorBoundary.wrap(TranslateChatBarIcon, { noop: true }), chatBarIcon: (slateProps: any) => (
<ErrorBoundary noop>
<TranslateChatBarIcon slateProps={slateProps} />
</ErrorBoundary>
)
}); });