Plugin
ImageFilename
Display the file name of images & GIFs as a tooltip when hovering over them
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { definePluginSettings } from "@api/Settings";8
import { Devs } from "@utils/constants";9
import definePlugin, { OptionType } from "@utils/types";10
11
const ImageExtensionRe = /\.(png|jpg|jpeg|gif|webp|avif)$/i;12
const GifHostRegex = /^(.+?\.)?(tenor|giphy|imgur)\.com$/i;13
14
const 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
22
export 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.showFullUrl46
? src47
: url.pathname.split("/").pop();48
} catch {49
return undefined;50
}51
}52
});53