advent-of-code-2023/wasm/index.html

49 lines
1.8 KiB
HTML
Raw Permalink Normal View History

2023-12-10 21:56:15 -07:00
<!DOCTYPE HTML>
<html>
<head>
<script type="module">
import init, * as advent from './pkg/advent_wasm.js';
init(); // Import advent lib and initialize wasm
document.getElementById("set-session-token").onclick = () => {
localStorage.setItem("auth", document.getElementById("session-token").value)
}
document.getElementById("calculate").onclick = async () => {
const auth = localStorage.getItem("auth");
const input = document.getElementById("input").value;
[...document.getElementById("days").children].map(async element => {
const day = element.id[3];
document.getElementById("day" + day).innerHTML = `Day ${day}: ${advent.solve(day, 1, input)}; ${advent.solve(day, 2, input)}`;
})
}
2023-12-10 21:56:15 -07:00
</script>
</head>
<body>
<label for="session-token">Token: </label>
<input id="session-token" type="text" />
<input id="set-session-token" type="button" value="Save" />
<br>
<br>
<label for="input">Input: </label>
<textarea id="input" rows="4" cols="50"></textarea>
<br>
<br>
<input id="calculate" type="button" value="Calculate all" />
<div id="days">
<p id="day1">Day 1: </p>
<p id="day2">Day 2: </p>
<p id="day3">Day 3: </p>
<p id="day4">Day 4: </p>
<p id="day5">Day 5: </p>
<p id="day6">Day 6: </p>
<p id="day7">Day 7: </p>
<p id="day8">Day 8: </p>
<p id="day9">Day 9: </p>
<p id="day10">Day 10: </p>
<p id="day11">Day 11: </p>
</div>
</body>
2023-12-10 21:56:15 -07:00
</html>