Fix module script scope: wire buttons via JS instead of HTML onclick

<script type="module"> doesn't expose functions to onclick attributes.
Replaced all onclick="fn()" with document.getElementById().onclick = fn
so buttons work from module scope.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-27 08:56:33 +04:00
parent 99da095a0f
commit 19f316c32b

View File

@@ -110,11 +110,11 @@ const WEB_HTML: &str = r##"<!DOCTYPE html>
<div class="sub">end-to-end encrypted messenger</div>
<div id="gen-section">
<button class="btn" onclick="doGenerate()">Generate Identity</button>
<button class="btn btn-alt" onclick="document.getElementById('recover-area').style.display='block'">Recover</button>
<button class="btn" id="btn-generate">Generate Identity</button>
<button class="btn btn-alt" id="btn-show-recover">Recover</button>
<div id="recover-area">
<textarea id="recover-input" placeholder="Paste your hex seed (64 chars)..." rows="2"></textarea>
<button class="btn" onclick="doRecover()">Recover Identity</button>
<button class="btn" id="btn-recover">Recover Identity</button>
</div>
</div>
@@ -124,7 +124,7 @@ const WEB_HTML: &str = r##"<!DOCTYPE html>
<div class="seed-display" id="my-seed"></div>
<div class="warn">SAVE YOUR SEED — only way to recover your identity</div>
<br>
<button class="btn" onclick="enterChat()">Enter Chat</button>
<button class="btn" id="btn-enter">Enter Chat</button>
</div>
</div>
@@ -139,7 +139,7 @@ const WEB_HTML: &str = r##"<!DOCTYPE html>
<div id="messages"></div>
<div id="bottom">
<textarea id="msg-input" placeholder="Message... (Enter to send)" rows="1"></textarea>
<button id="send-btn" onclick="doSend()">&#9654;</button>
<button id="send-btn">&#9654;</button>
</div>
</div>
@@ -639,6 +639,13 @@ $input.addEventListener('input', function() {
this.style.height = Math.min(this.scrollHeight, 120) + 'px';
});
// Wire up buttons (module scope can't use onclick in HTML)
document.getElementById('btn-generate').onclick = () => doGenerate();
document.getElementById('btn-show-recover').onclick = () => document.getElementById('recover-area').style.display = 'block';
document.getElementById('btn-recover').onclick = () => doRecover();
document.getElementById('btn-enter').onclick = () => enterChat();
document.getElementById('send-btn').onclick = () => doSend();
// Initialize WASM and auto-load
(async function() {
try {