aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2025-09-03 17:37:36 +0200
committerGitHub <noreply@github.com>2025-09-03 17:37:36 +0200
commit0d2a3994e203755702ebe4afbd0f3c721ee8ce38 (patch)
tree9347303eaa9daad5e10420ab1d90e24593c70df1 /webAO/dom
parent8e46e304f4defc7f9f4eb01922812b28a8585307 (diff)
parent035951baf3819f56093f7156b345689aa5093f28 (diff)
Merge pull request #270 from AttorneyOnline/ext
Let the webhost specify the extensions use
Diffstat (limited to 'webAO/dom')
-rw-r--r--webAO/dom/updateBackgroundPreview.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/webAO/dom/updateBackgroundPreview.ts b/webAO/dom/updateBackgroundPreview.ts
index 61eec58..2b8a18b 100644
--- a/webAO/dom/updateBackgroundPreview.ts
+++ b/webAO/dom/updateBackgroundPreview.ts
@@ -1,5 +1,20 @@
import { AO_HOST } from "../client/aoHost";
-import tryUrls from "../utils/tryUrls";
+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.
@@ -20,7 +35,7 @@ export function updateBackgroundPreview() {
} else {
background_filename.style.display = "none";
}
- tryUrls(
+ tryBackgroundUrls(
`${AO_HOST}background/${encodeURI(
background_select.value.toLowerCase(),
)}/defenseempty`,