-
Notifications
You must be signed in to change notification settings - Fork 7
/
basics.html
48 lines (48 loc) · 1.45 KB
/
basics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE HTML>
<html>
<head><title>Basics</title>
<style>
body, input, button {font-size: 48px;}
</style>
</head>
<body>
<main></main>
<script type=module>
import {lindt, replace_content, DOM} from "https://rosuav.github.io/choc/factory.js";
const {BUTTON, INPUT, TABLE, TD, TH, TR} = lindt;
const lbls = ["Idl", "Reg", "Str", "Par", "Pier", "Ult"];
const {values = [2500, 15000, 30000, 50000, 0, 0], nexts = [0, 0, 0, 0, 0, 0]} = JSON.parse(localStorage.getItem("state")) || {};
function render() {
replace_content("main", TABLE([
TR([TH(""), TH("Now"), TH("Next"), TH("Sum")]),
lbls.map((lbl, i) => TR([
TH(lbl),
TD(INPUT({class: "now", "data-idx": i, type: "number", value: ""+values[i]})),
TD(INPUT({class: "next", "data-idx": i, type: "number", value: ""+nexts[i]})),
TD("" + (values[i] + (values[i+1] || 0))),
])),
TR([TD(), TD("Migrate"), TD(BUTTON({id: "migrate"}, "<==")), TD("" + values.reduce((a,b)=>a+b))]),
]));
localStorage.setItem("state", JSON.stringify({values, nexts}));
}
on("change", ".now", e => {
const val = +e.match.value;
values[e.match.dataset.idx] = val;
nexts[e.match.dataset.idx] = Math.max(Math.floor(val * 0.9), 1);
render();
});
on("change", ".next", e => {
nexts[e.match.dataset.idx] = +e.match.value;
render();
});
on("click", "#migrate", e => {
for (let i = 0; i < lbls.length; ++i) {
values[i] = nexts[i];
nexts[i] = Math.max(Math.floor(values[i] * 0.9), 1);
}
render();
});
render();
</script>
</body>
</html>