diff options
Diffstat (limited to 'claude-julia/client.ts')
| -rw-r--r-- | claude-julia/client.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/claude-julia/client.ts b/claude-julia/client.ts new file mode 100644 index 0000000..200a8e6 --- /dev/null +++ b/claude-julia/client.ts @@ -0,0 +1,28 @@ +const textDecoder = new TextDecoder(); + +async function request() { + let el_response = document.getElementById("response")!; + el_response.innerHTML = "Thinking..."; + + let code: string = (document.getElementById("code") as HTMLTextAreaElement).value + let req = { + method: 'POST', + body: code + }; + let res = await window.fetch("/query", req); + let body: string = textDecoder.decode(await res.bytes()); + + const parser = new DOMParser(); + const doc = parser.parseFromString(body, "text/html"); + let html = ''; + for (let imp of doc.querySelectorAll('improvement')) { + let orig_code = imp.querySelector('original_code')!.innerHTML; + let impr_code = imp.querySelector('improved_code')!.innerHTML; + let expl = imp.querySelector('explanation')!.innerHTML; + html += '<div class="code"><pre class="orig">'+orig_code+'</pre>'; + html += '<pre class="impr">'+impr_code+'</pre></div>'; + html += '<div class="expl">'+expl+'</div><hr/>'; + } + + el_response.innerHTML = html; +} |
