Plugin

ImageFilename

Display the file name of images & GIFs as a tooltip when hovering over them

Media Utility
index.ts
Download

Source

src/plugins/imageFilename/index.ts
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import { definePluginSettings } from "@api/Settings";
8import { Devs } from "@utils/constants";
9import definePlugin, { OptionType } from "@utils/types";
10
11const ImageExtensionRe = /\.(png|jpg|jpeg|gif|webp|avif)$/i;
12const GifHostRegex = /^(.+?\.)?(tenor|giphy|imgur)\.com$/i;
13
14const settings = definePluginSettings({
15 showFullUrl: {
16 description: "Show the full URL of the image instead of just the file name. Always enabled for GIFs because they usually have no meaningful file name",
17 type: OptionType.BOOLEAN,
18 default: false,
19 },
20});
21
22export default definePlugin({
23 name: "ImageFilename",
24 authors: [Devs.Ven],
25 description: "Display the file name of images & GIFs as a tooltip when hovering over them",
26 tags: ["Media", "Utility"],
27 settings,
28
29 patches: [
30 {
31 find: ".RESPONSIVE?",
32 replacement: {
33 match: /(?="data-role":"img","data-safe-src":)(?<=href:(\i).+?)/,
34 replace: "title:$self.getTitle($1),"
35 }
36 },
37 ],
38
39 getTitle(src: string) {
40 try {
41 const url = new URL(src);
42 const isGif = GifHostRegex.test(url.hostname);
43 if (!isGif && !ImageExtensionRe.test(url.pathname)) return undefined;
44
45 return isGif || settings.store.showFullUrl
46 ? src
47 : url.pathname.split("/").pop();
48 } catch {
49 return undefined;
50 }
51 }
52});
53