Plugin
ImageFilename
Display the file name of images & GIFs as a tooltip when hovering over them
1
import { definePluginSettings } from "@api/Settings";2
import { Devs } from "@utils/constants";3
import definePlugin, { OptionType } from "@utils/types";4
5
const ImageExtensionRe = /\.(png|jpg|jpeg|gif|webp|avif)$/i;6
const GifHostRegex = /^(.+?\.)?(tenor|giphy|imgur)\.com$/i;7
8
const settings = definePluginSettings({9
showFullUrl: {10
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",11
type: OptionType.BOOLEAN,12
default: false,13
},14
});15
16
export default definePlugin({17
name: "ImageFilename",18
authors: [Devs.Ven],19
description: "Display the file name of images & GIFs as a tooltip when hovering over them",20
tags: ["Media", "Utility"],21
settings,22
23
patches: [24
{25
find: ".RESPONSIVE?",26
replacement: {27
match: /(?="data-role":"img","data-safe-src":)(?<=href:(\i).+?)/,28
replace: "title:$self.getTitle($1),"29
}30
},31
],32
33
getTitle(src: string) {34
try {35
const url = new URL(src);36
const isGif = GifHostRegex.test(url.hostname);37
if (!isGif && !ImageExtensionRe.test(url.pathname)) return undefined;38
39
return isGif || settings.store.showFullUrl40
? src41
: url.pathname.split("/").pop();42
} catch {43
return undefined;44
}45
}46
});47