From 74300e0a6963dec7f83dc9f21f93736be9990b59 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Thu, 18 Jan 2024 00:58:40 +0100 Subject: [PATCH] WebContextMenus: only force png on copy image, not save image --- src/plugins/webContextMenus.web/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/webContextMenus.web/index.ts b/src/plugins/webContextMenus.web/index.ts index ec3070b11..5f6beca2c 100644 --- a/src/plugins/webContextMenus.web/index.ts +++ b/src/plugins/webContextMenus.web/index.ts @@ -49,7 +49,7 @@ const settings = definePluginSettings({ const MEDIA_PROXY_URL = "https://media.discordapp.net"; const CDN_URL = "https://cdn.discordapp.com"; -function fixImageUrl(urlString: string) { +function fixImageUrl(urlString: string, explodeWebp: boolean) { const url = new URL(urlString); if (url.origin === CDN_URL) return urlString; if (url.origin === MEDIA_PROXY_URL) return CDN_URL + url.pathname; @@ -57,7 +57,9 @@ function fixImageUrl(urlString: string) { url.searchParams.delete("width"); url.searchParams.delete("height"); url.searchParams.set("quality", "lossless"); - if (url.searchParams.get("format") === "webp") url.searchParams.set("format", "png"); + if (explodeWebp && url.searchParams.get("format") === "webp") + url.searchParams.set("format", "png"); + return url.toString(); } @@ -197,7 +199,7 @@ export default definePlugin({ ], async copyImage(url: string) { - url = fixImageUrl(url); + url = fixImageUrl(url, true); let imageData = await fetch(url).then(r => r.blob()); if (imageData.type !== "image/png") { @@ -229,7 +231,7 @@ export default definePlugin({ }, async saveImage(url: string) { - url = fixImageUrl(url); + url = fixImageUrl(url, false); const data = await fetchImage(url); if (!data) return;