Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 2 additions & 34 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Unity Voice Chat</title>
<script>
(() => {
const href = window.location.href;
const pathname = window.location.pathname || '';
const lastSegment = pathname.substring(pathname.lastIndexOf('/') + 1);

const directoryUrl = href.endsWith('/')
? href
: lastSegment && lastSegment.includes('.')
? href.substring(0, href.lastIndexOf('/') + 1)
: `${href}/`;

window.__UNITY_VOICE_DIRECTORY_URL__ = directoryUrl;

const resolveAsset = (relativePath) => {
try {
return new URL(relativePath, directoryUrl).toString();
} catch (error) {
console.error('Failed to resolve asset path:', error);
return relativePath;
}
};

const styleLink = document.createElement('link');
styleLink.rel = 'stylesheet';
styleLink.href = resolveAsset('style.css');
document.head.appendChild(styleLink);

const script = document.createElement('script');
script.defer = true;
script.src = resolveAsset('app.js');
document.head.appendChild(script);
})();
</script>
<link rel="stylesheet" href="./style.css">
<script defer src="./app.js"></script>
</head>
<body>
<div id="background" aria-hidden="true"></div>
Expand Down