Plugin

BetterGifAltText

Change GIF alt text from simply being 'GIF' to containing the gif tags / filename

Media Accessibility Customisation
index.ts
Download

Source

src/plugins/betterGifAltText/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 { Devs } from "@utils/constants";
8import definePlugin from "@utils/types";
9
10export default definePlugin({
11 name: "BetterGifAltText",
12 authors: [Devs.Ven],
13 description:
14 "Change GIF alt text from simply being 'GIF' to containing the gif tags / filename",
15 tags: ["Media", "Accessibility", "Customisation"],
16 patches: [
17 {
18 find: ".modalContext})};",
19 replacement: {
20 match: /(return.{0,10}\.jsx.{0,50}isWindowFocused)/,
21 replace:
22 "$self.altify(e);$1",
23 },
24 },
25 {
26 find: "#{intl::GIF}",
27 replacement: {
28 match: /alt:(\i)=(\i\.\i\.string\(\i\.\i#{intl::GIF}\))(?=,[^}]*\}=(\i))/,
29 replace:
30 // rename prop so we can always use default value
31 "alt_$$:$1=$self.altify($3)||$2",
32 },
33 },
34 ],
35
36 altify(props: any) {
37 props.alt ??= "GIF";
38 if (props.alt !== "GIF") return props.alt;
39
40 let url: string = props.original || props.src;
41 try {
42 url = decodeURI(url);
43 } catch { }
44
45 let name = url
46 .slice(url.lastIndexOf("/") + 1)
47 .replace(/\d/g, "") class="ts-cmt">// strip numbers
48 .replace(/.gif$/, "") class="ts-cmt">// strip extension
49 .split(/[,\-_ ]+/g)
50 .slice(0, 20)
51 .join(" ");
52 if (name.length > 300) {
53 name = name.slice(0, 300) + "...";
54 }
55
56 if (name) props.alt += ` - ${name}`;
57
58 return props.alt;
59 },
60});
61