From 1ba59be463abe60448b0eb7da157251c393c0590 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 10:29:13 +0200 Subject: bgurls --- webAO/dom/updateBackgroundPreview.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/dom/updateBackgroundPreview.ts') diff --git a/webAO/dom/updateBackgroundPreview.ts b/webAO/dom/updateBackgroundPreview.ts index 61eec58..61186e0 100644 --- a/webAO/dom/updateBackgroundPreview.ts +++ b/webAO/dom/updateBackgroundPreview.ts @@ -1,5 +1,5 @@ import { AO_HOST } from "../client/aoHost"; -import tryUrls from "../utils/tryUrls"; +import tryBackgroundUrls from "../utils/tryBackgroundUrls"; /** * Update background preview. @@ -20,7 +20,7 @@ export function updateBackgroundPreview() { } else { background_filename.style.display = "none"; } - tryUrls( + tryBackgroundUrls( `${AO_HOST}background/${encodeURI( background_select.value.toLowerCase(), )}/defenseempty`, -- cgit From 183fd0fdddbcf194eec08f8e79e6a1709e18d3a9 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 12:20:42 +0200 Subject: also do bgs --- webAO/dom/updateBackgroundPreview.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'webAO/dom/updateBackgroundPreview.ts') diff --git a/webAO/dom/updateBackgroundPreview.ts b/webAO/dom/updateBackgroundPreview.ts index 61186e0..2b8a18b 100644 --- a/webAO/dom/updateBackgroundPreview.ts +++ b/webAO/dom/updateBackgroundPreview.ts @@ -1,5 +1,20 @@ import { AO_HOST } from "../client/aoHost"; -import tryBackgroundUrls from "../utils/tryBackgroundUrls"; +import fileExists from "../utils/fileExists"; +import transparentPng from "../constants/transparentPng"; + +const urlExtensionsToTry = [".png", ".gif", ".webp", ".apng"]; +const tryBackgroundUrls = async (url: string) => { + for (let i = 0; i < urlExtensionsToTry.length; i++) { + const extension = urlExtensionsToTry[i]; + const fullFileUrl = url + extension; + const exists = await fileExists(fullFileUrl); + if (exists) { + return fullFileUrl; + } + } + return transparentPng; +}; +export default tryBackgroundUrls; /** * Update background preview. -- cgit