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