new plugin CopyFileContents ~Easily copy text file attachments contents (#2790)
This commit is contained in:
parent
00276cad7c
commit
d5eaae9d51
5 changed files with 81 additions and 4 deletions
|
@ -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
|
* Discord's copy icon, as seen in the user panel popout on the right of the username and in large code blocks
|
||||||
* your own username in the bottom left user panel
|
|
||||||
*/
|
*/
|
||||||
export function CopyIcon(props: IconProps) {
|
export function CopyIcon(props: IconProps) {
|
||||||
return (
|
return (
|
||||||
|
@ -76,8 +75,9 @@ export function CopyIcon(props: IconProps) {
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
>
|
>
|
||||||
<g fill="currentColor">
|
<g fill="currentColor">
|
||||||
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1z" />
|
<path d="M3 16a1 1 0 0 1-1-1v-5a8 8 0 0 1 8-8h5a1 1 0 0 1 1 1v.5a.5.5 0 0 1-.5.5H10a6 6 0 0 0-6 6v5.5a.5.5 0 0 1-.5.5H3Z" />
|
||||||
<path d="M15 5H8c-1.1 0-1.99.9-1.99 2L6 21c0 1.1.89 2 1.99 2H19c1.1 0 2-.9 2-2V11l-6-6zM8 21V7h6v5h5v9H8z" />
|
<path d="M6 18a4 4 0 0 0 4 4h8a4 4 0 0 0 4-4v-4h-3a5 5 0 0 1-5-5V6h-4a4 4 0 0 0-4 4v8Z" />
|
||||||
|
<path d="M21.73 12a3 3 0 0 0-.6-.88l-4.25-4.24a3 3 0 0 0-.88-.61V9a3 3 0 0 0 3 3h2.73Z" />
|
||||||
</g>
|
</g>
|
||||||
</Icon>
|
</Icon>
|
||||||
);
|
);
|
||||||
|
|
5
src/plugins/CopyFileContents/README.md
Normal file
5
src/plugins/CopyFileContents/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# CopyFileContents
|
||||||
|
|
||||||
|
Adds a button to text file attachments to copy their contents.
|
||||||
|
|
||||||
|
![](https://github.com/user-attachments/assets/b1a0f6f4-106f-4953-94d9-4c5ef5810bca)
|
60
src/plugins/CopyFileContents/index.tsx
Normal file
60
src/plugins/CopyFileContents/index.tsx
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* 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/misc";
|
||||||
|
import definePlugin from "@utils/types";
|
||||||
|
import { Tooltip, useState } from "@webpack/common";
|
||||||
|
|
||||||
|
const CheckMarkIcon = () => {
|
||||||
|
return <svg width="24" height="24" viewBox="0 0 24 24">
|
||||||
|
<path fill="currentColor" d="M21.7 5.3a1 1 0 0 1 0 1.4l-12 12a1 1 0 0 1-1.4 0l-6-6a1 1 0 1 1 1.4-1.4L9 16.58l11.3-11.3a1 1 0 0 1 1.4 0Z"></path>
|
||||||
|
</svg>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "CopyFileContents",
|
||||||
|
description: "Adds a button to text file attachments to copy their 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 (
|
||||||
|
<Tooltip text={recentlyCopied ? "Copied!" : bytesLeft > 0 ? "File too large to copy" : "Copy File Contents"}>
|
||||||
|
{tooltipProps => (
|
||||||
|
<div
|
||||||
|
{...tooltipProps}
|
||||||
|
className="vc-cfc-button"
|
||||||
|
role="button"
|
||||||
|
onClick={() => {
|
||||||
|
if (!recentlyCopied && bytesLeft <= 0) {
|
||||||
|
copyWithToast(fileContents);
|
||||||
|
setRecentlyCopied(true);
|
||||||
|
setTimeout(() => setRecentlyCopied(false), 2000);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{recentlyCopied ? <CheckMarkIcon /> : bytesLeft > 0 ? <NoEntrySignIcon color="var(--channel-icon)" /> : <CopyIcon />}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}, { noop: true }),
|
||||||
|
});
|
8
src/plugins/CopyFileContents/style.css
Normal file
8
src/plugins/CopyFileContents/style.css
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
.vc-cfc-button {
|
||||||
|
color: var(--interactive-normal);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-cfc-button:hover {
|
||||||
|
color: var(--interactive-hover);
|
||||||
|
}
|
|
@ -550,6 +550,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
name: "Lumap",
|
name: "Lumap",
|
||||||
id: 585278686291427338n,
|
id: 585278686291427338n,
|
||||||
},
|
},
|
||||||
|
Obsidian: {
|
||||||
|
name: "Obsidian",
|
||||||
|
id: 683171006717755446n,
|
||||||
|
},
|
||||||
SerStars: {
|
SerStars: {
|
||||||
name: "SerStars",
|
name: "SerStars",
|
||||||
id: 861631850681729045n,
|
id: 861631850681729045n,
|
||||||
|
|
Loading…
Reference in a new issue