From 7240c03e1630e991f6fe80233e5577f1dce81abc Mon Sep 17 00:00:00 2001 From: Obsidian <108832807+Obsidianninja11@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:41:52 -0800 Subject: [PATCH 1/9] Create CopyFileContents plugin --- src/components/Icons.tsx | 8 ++--- src/plugins/CopyFileContents/index.tsx | 50 ++++++++++++++++++++++++++ src/plugins/CopyFileContents/style.css | 8 +++++ src/utils/constants.ts | 4 +++ 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/plugins/CopyFileContents/index.tsx create mode 100644 src/plugins/CopyFileContents/style.css diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index 7ba078d333..fa142a18ce 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -65,8 +65,7 @@ export function LinkIcon({ height = 24, width = 24, className }: IconProps) { } /** - * Discord's copy icon, as seen in the user popout right of the username when clicking - * your own username in the bottom left user panel + * Discord's copy icon, as seen in the user panel popout on the right of the username and in large code blocks */ export function CopyIcon(props: IconProps) { return ( @@ -76,8 +75,9 @@ export function CopyIcon(props: IconProps) { viewBox="0 0 24 24" > - - + + + ); diff --git a/src/plugins/CopyFileContents/index.tsx b/src/plugins/CopyFileContents/index.tsx new file mode 100644 index 0000000000..8e1e2c3313 --- /dev/null +++ b/src/plugins/CopyFileContents/index.tsx @@ -0,0 +1,50 @@ +import "./style.css"; + +import definePlugin from "@utils/types"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Clipboard, showToast, Toasts, Tooltip, useState } from "@webpack/common"; +import { CopyIcon, NoEntrySignIcon } from "@components/Icons"; +import { Devs } from "@utils/constants"; + +const CheckMarkIcon = () => { + return ; +}; + +export default definePlugin({ + name: "CopyFileContents", + description: "Adds a button to copy text file attachment contents.", + authors: [Devs.Obsidian, Devs.Nuckyz], + patches: [ + { + find: ".Messages.PREVIEW_BYTES_LEFT.format(", + replacement: { + match: /\.footerGap.+?url:\i,fileName:\i,fileSize:\i}\),(?<=fileContents:(\i),bytesLeft:(\i).+?)/g, + replace: "$&$self.AddCopyButton({ fileContents: $1, bytesLeft: $2 })," + } + } + ], + AddCopyButton: ErrorBoundary.wrap(({ fileContents, bytesLeft }: { fileContents: string, bytesLeft: number; }) => { + const [recentlyCopied, setRecentlyCopied] = useState(false); + return ( + 0 ? "File too large to copy" : "Copy File Contents"}> + {(tooltipProps) => ( +
{ + if (bytesLeft <= 0) { + Clipboard.copy(fileContents); + setRecentlyCopied(true); + } + }} + > + {recentlyCopied ? : bytesLeft > 0 ? : } +
+ )} +
+ ); + }, { noop: true }), +}); diff --git a/src/plugins/CopyFileContents/style.css b/src/plugins/CopyFileContents/style.css new file mode 100644 index 0000000000..05f3899c0b --- /dev/null +++ b/src/plugins/CopyFileContents/style.css @@ -0,0 +1,8 @@ +.vc-cfc-button { + color: var(--interactive-normal); + cursor: pointer; +} + +.vc-cfc-button:hover { + color: var(--interactive-hover); +} \ No newline at end of file diff --git a/src/utils/constants.ts b/src/utils/constants.ts index febb8f9afe..8a5b41e064 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -546,6 +546,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Lumap", id: 585278686291427338n, }, + Obsidian: { + name: "Obsidian", + id: 683171006717755446n, + }, } satisfies Record); // iife so #__PURE__ works correctly From dbf8916e86c101d088c0ae2fcd18d57d7e34695f Mon Sep 17 00:00:00 2001 From: Obsidian <108832807+Obsidianninja11@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:55:52 -0800 Subject: [PATCH 2/9] Fix lint formatting --- src/plugins/CopyFileContents/index.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/CopyFileContents/index.tsx b/src/plugins/CopyFileContents/index.tsx index 8e1e2c3313..8349ca1c34 100644 --- a/src/plugins/CopyFileContents/index.tsx +++ b/src/plugins/CopyFileContents/index.tsx @@ -1,10 +1,16 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + import "./style.css"; -import definePlugin from "@utils/types"; import ErrorBoundary from "@components/ErrorBoundary"; -import { Clipboard, showToast, Toasts, Tooltip, useState } from "@webpack/common"; import { CopyIcon, NoEntrySignIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { Clipboard, Tooltip, useState } from "@webpack/common"; const CheckMarkIcon = () => { return
Date: Sun, 25 Aug 2024 19:04:12 -0800 Subject: [PATCH 3/9] Small fixes --- src/plugins/CopyFileContents/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/CopyFileContents/index.tsx b/src/plugins/CopyFileContents/index.tsx index 8349ca1c34..e7724351d4 100644 --- a/src/plugins/CopyFileContents/index.tsx +++ b/src/plugins/CopyFileContents/index.tsx @@ -27,11 +27,11 @@ export default definePlugin({ find: ".Messages.PREVIEW_BYTES_LEFT.format(", replacement: { match: /\.footerGap.+?url:\i,fileName:\i,fileSize:\i}\),(?<=fileContents:(\i),bytesLeft:(\i).+?)/g, - replace: "$&$self.AddCopyButton({ fileContents: $1, bytesLeft: $2 })," + replace: "$&$self.addCopyButton({fileContents:$1,bytesLeft:$2})," } } ], - AddCopyButton: ErrorBoundary.wrap(({ fileContents, bytesLeft }: { fileContents: string, bytesLeft: number; }) => { + addCopyButton: ErrorBoundary.wrap(({ fileContents, bytesLeft }: { fileContents: string, bytesLeft: number; }) => { const [recentlyCopied, setRecentlyCopied] = useState(false); return ( 0 ? "File too large to copy" : "Copy File Contents"}> From 53fa510ed82d21ed8af02cd7f545b039fa91c353 Mon Sep 17 00:00:00 2001 From: Obsidian <108832807+Obsidianninja11@users.noreply.github.com> Date: Fri, 30 Aug 2024 04:10:04 -0800 Subject: [PATCH 4/9] Formatting --- src/plugins/CopyFileContents/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/CopyFileContents/index.tsx b/src/plugins/CopyFileContents/index.tsx index e7724351d4..7bbd48b77c 100644 --- a/src/plugins/CopyFileContents/index.tsx +++ b/src/plugins/CopyFileContents/index.tsx @@ -13,7 +13,7 @@ import definePlugin from "@utils/types"; import { Clipboard, Tooltip, useState } from "@webpack/common"; const CheckMarkIcon = () => { - return