diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index 7ba078d33..fa142a18c 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/components/VencordSettings/PatchHelperTab.tsx b/src/components/VencordSettings/PatchHelperTab.tsx index e09a1dbf3..fd33c09df 100644 --- a/src/components/VencordSettings/PatchHelperTab.tsx +++ b/src/components/VencordSettings/PatchHelperTab.tsx @@ -382,6 +382,7 @@ function PatchHelper() { Code + )} diff --git a/src/plugins/CopyFileContents/README.md b/src/plugins/CopyFileContents/README.md new file mode 100644 index 000000000..18dc2d3df --- /dev/null +++ b/src/plugins/CopyFileContents/README.md @@ -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) diff --git a/src/plugins/CopyFileContents/index.tsx b/src/plugins/CopyFileContents/index.tsx new file mode 100644 index 000000000..13b649174 --- /dev/null +++ b/src/plugins/CopyFileContents/index.tsx @@ -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 + + ; +}; + +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 ( + 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 }), +}); diff --git a/src/plugins/CopyFileContents/style.css b/src/plugins/CopyFileContents/style.css new file mode 100644 index 000000000..c643cf0f0 --- /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); +} diff --git a/src/plugins/timeBarAllActivities/README.md b/src/plugins/timeBarAllActivities/README.md new file mode 100644 index 000000000..59f0451c2 --- /dev/null +++ b/src/plugins/timeBarAllActivities/README.md @@ -0,0 +1,5 @@ +# TimeBarAllActivities + +Adds the Spotify time bar to all activities if they have start and end timestamps. + +![](https://github.com/user-attachments/assets/9fbbe33c-8218-43c9-8b8d-f907a4e809fe) diff --git a/src/plugins/timeBarAllActivities/index.ts b/src/plugins/timeBarAllActivities/index.ts deleted file mode 100644 index dcb809fd4..000000000 --- a/src/plugins/timeBarAllActivities/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; - -export default definePlugin({ - name: "TimeBarAllActivities", - description: "Adds the Spotify time bar to all activities if they have start and end timestamps", - authors: [Devs.fawn], - patches: [ - { - find: "}renderTimeBar(", - replacement: { - match: /renderTimeBar\((.{1,3})\){.{0,50}?let/, - replace: "renderTimeBar($1){let" - } - } - ], -}); diff --git a/src/plugins/timeBarAllActivities/index.tsx b/src/plugins/timeBarAllActivities/index.tsx new file mode 100644 index 000000000..04f7ff9e7 --- /dev/null +++ b/src/plugins/timeBarAllActivities/index.tsx @@ -0,0 +1,76 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { findComponentByCodeLazy } from "@webpack"; + +interface Activity { + timestamps?: ActivityTimestamps; +} + +interface ActivityTimestamps { + start?: string; + end?: string; +} + +const ActivityTimeBar = findComponentByCodeLazy(".Millis.HALF_SECOND", ".bar", ".progress"); + +export const settings = definePluginSettings({ + hideActivityDetailText: { + type: OptionType.BOOLEAN, + description: "Hide the large title text next to the activity", + default: true, + }, + hideActivityTimerBadges: { + type: OptionType.BOOLEAN, + description: "Hide the timer badges next to the activity", + default: true, + } +}); + +export default definePlugin({ + name: "TimeBarAllActivities", + description: "Adds the Spotify time bar to all activities if they have start and end timestamps", + authors: [Devs.fawn, Devs.niko], + settings, + patches: [ + { + find: ".Messages.USER_ACTIVITY_PLAYING", + replacement: [ + // Insert Spotify time bar component + { + match: /\(0,.{0,30}activity:(\i),className:\i\.badges\}\)/g, + replace: "$&,$self.getTimeBar($1)" + }, + // Hide the large title on listening activities, to make them look more like Spotify (also visible from hovering over the large icon) + { + match: /(\i).type===(\i\.\i)\.WATCHING/, + replace: "($self.settings.store.hideActivityDetailText&&$self.isActivityTimestamped($1)&&$1.type===$2.LISTENING)||$&" + } + ] + }, + // Hide the "badge" timers that count the time since the activity starts + { + find: ".TvIcon).otherwise", + replacement: { + match: /null!==\(\i=null===\(\i=(\i)\.timestamps\).{0,50}created_at/, + replace: "($self.settings.store.hideActivityTimerBadges&&$self.isActivityTimestamped($1))?null:$&" + } + } + ], + + isActivityTimestamped(activity: Activity) { + return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null; + }, + + getTimeBar(activity: Activity) { + if (this.isActivityTimestamped(activity)) { + return ; + } + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index c264ff41d..5a12c1667 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -554,10 +554,18 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "sadan", id: 521819891141967883n }, + Obsidian: { + name: "Obsidian", + id: 683171006717755446n, + }, SerStars: { name: "SerStars", id: 861631850681729045n, }, + niko: { + name: "niko", + id: 341377368075796483n, + }, } satisfies Record); // iife so #__PURE__ works correctly