mirror of
https://github.com/Equicord/Equicord.git
synced 2025-02-23 08:39:24 -05:00
BannersEverywhere: Fix Animate on Everything
This commit is contained in:
parent
fa761b895c
commit
0e0674fd98
1 changed files with 49 additions and 3 deletions
|
@ -21,7 +21,7 @@ interface iUSRBG extends Plugin {
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
animate: {
|
animate: {
|
||||||
description: "Animate Discord banners (NOT USRBG)",
|
description: "Animate banners",
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
@ -73,13 +73,59 @@ export default definePlugin({
|
||||||
memberListBannerHook(user: User) {
|
memberListBannerHook(user: User) {
|
||||||
let url = this.getBanner(user.id);
|
let url = this.getBanner(user.id);
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
if (!settings.store.animate) url = url.replace(".gif", ".png");
|
if (!settings.store.animate) {
|
||||||
|
// Discord Banners
|
||||||
|
url = url.replace(".gif", ".png");
|
||||||
|
// Usrbg Banners
|
||||||
|
this.gifToPng(url)
|
||||||
|
.then(pngUrl => {
|
||||||
|
const imgElement = document.getElementById(`vc-banners-everywhere-${user.id}`) as HTMLImageElement;
|
||||||
|
if (imgElement) {
|
||||||
|
imgElement.src = pngUrl;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<img src={url} className="vc-banners-everywhere-memberlist"></img>
|
<img id={`vc-banners-everywhere-${user.id}`} src={url} className="vc-banners-everywhere-memberlist"></img>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async checkImageExists(url: string): Promise<boolean> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => resolve(true);
|
||||||
|
img.onerror = () => resolve(false);
|
||||||
|
img.src = url;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async gifToPng(url: string): Promise<string> {
|
||||||
|
const exists = await this.checkImageExists(url);
|
||||||
|
if (!exists) return "";
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const img = new Image();
|
||||||
|
img.crossOrigin = "anonymous";
|
||||||
|
img.onload = () => {
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = img.width;
|
||||||
|
canvas.height = img.height;
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
if (ctx) {
|
||||||
|
ctx.drawImage(img, 0, 0);
|
||||||
|
const pngDataUrl = canvas.toDataURL("image/png");
|
||||||
|
resolve(pngDataUrl);
|
||||||
|
} else {
|
||||||
|
reject(new Error("Failed to get canvas context."));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
img.onerror = err => reject(err);
|
||||||
|
img.src = url;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getBanner(userId: string): string | undefined {
|
getBanner(userId: string): string | undefined {
|
||||||
if (Vencord.Plugins.isPluginEnabled("USRBG") && (Vencord.Plugins.plugins.USRBG as iUSRBG).userHasBackground(userId)) {
|
if (Vencord.Plugins.isPluginEnabled("USRBG") && (Vencord.Plugins.plugins.USRBG as iUSRBG).userHasBackground(userId)) {
|
||||||
let banner = (Vencord.Plugins.plugins.USRBG as iUSRBG).getImageUrl(userId);
|
let banner = (Vencord.Plugins.plugins.USRBG as iUSRBG).getImageUrl(userId);
|
||||||
|
|
Loading…
Add table
Reference in a new issue