/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import "./style.css"; import ErrorBoundary from "@components/ErrorBoundary"; import { CopyIcon, NoEntrySignIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; import { copyWithToast } from "@utils/discord"; import definePlugin from "@utils/types"; import { Tooltip, useState } from "@webpack/common"; const CheckMarkIcon = () => { return ; }; export default definePlugin({ name: "CopyFileContents", description: "Adds a button to text file attachments to copy their contents", tags: ["Utility"], authors: [Devs.Obsidian, Devs.Nuckyz], patches: [ { find: "#{intl::PREVIEW_BYTES_LEFT}", replacement: [ // Inline preview { match: /fileContents:(\i),bytesLeft:(\i)\}\):null,/, replace: "$&$self.addCopyButton({fileContents:$1,bytesLeft:$2})," }, // Modal { match: /align:"\i"\}\),(?=\(0,\i\.jsx\)\(\i,\{wordWrap:\i,setWordWrap:\i)/, replace: "$&$self.addCopyButton(arguments[0])," } ] } ], 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 (!recentlyCopied && bytesLeft <= 0) { copyWithToast(fileContents); setRecentlyCopied(true); setTimeout(() => setRecentlyCopied(false), 2000); } }} > {recentlyCopied ? : bytesLeft > 0 ? : }
)}
); }, { noop: true }), });