Plugin
BetterGifAltText
Change GIF alt text from simply being 'GIF' to containing the gif tags / filename
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { Devs } from "@utils/constants";8
import definePlugin from "@utils/types";9
10
export default definePlugin({11
name: "BetterGifAltText",12
authors: [Devs.Ven],13
description:14
"Change GIF alt text from simply being 039;GIF039; 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 value31
"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 = url46
.slice(url.lastIndexOf("/") + 1)47
.replace(/\d/g, "") class="ts-cmt">// strip numbers48
.replace(/.gif$/, "") class="ts-cmt">// strip extension49
.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