From bce83753c71efbcff36164d29dcb8796d1534491 Mon Sep 17 00:00:00 2001 From: G-Fourteen Date: Fri, 31 Oct 2025 18:18:57 -0600 Subject: [PATCH] Fix asset loading for GitHub Pages --- app.js | 34 +++++++++++++++++++++------------- index.html | 36 ++---------------------------------- 2 files changed, 23 insertions(+), 47 deletions(-) diff --git a/app.js b/app.js index d449797..e06c020 100644 --- a/app.js +++ b/app.js @@ -14,22 +14,30 @@ let hasMicPermission = false; const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; const synth = window.speechSynthesis; -const directoryUrl = window.__UNITY_VOICE_DIRECTORY_URL__ - ?? (() => { - const href = window.location.href; - const pathname = window.location.pathname || ''; - const lastSegment = pathname.substring(pathname.lastIndexOf('/') + 1); - - if (href.endsWith('/')) { - return href; +const currentScript = document.currentScript; +const directoryUrl = (() => { + if (currentScript?.src) { + try { + return new URL('./', currentScript.src).toString(); + } catch (error) { + console.error('Failed to derive directory from script src:', error); } + } - if (lastSegment && lastSegment.includes('.')) { - return href.substring(0, href.lastIndexOf('/') + 1); - } + const href = window.location.href; + const pathname = window.location.pathname || ''; + const lastSegment = pathname.substring(pathname.lastIndexOf('/') + 1); + + if (href.endsWith('/')) { + return href; + } + + if (lastSegment && lastSegment.includes('.')) { + return href.substring(0, href.lastIndexOf('/') + 1); + } - return `${href}/`; - })(); + return `${href}/`; +})(); function resolveAssetPath(relativePath) { try { diff --git a/index.html b/index.html index 0fcd087..d7fa67b 100644 --- a/index.html +++ b/index.html @@ -4,40 +4,8 @@ Unity Voice Chat - + +