-
Notifications
You must be signed in to change notification settings - Fork 1
/
anydice.html
53 lines (51 loc) · 1.83 KB
/
anydice.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
49
50
51
52
53
<html>
<head>
<meta charset="UTF-8">
<meta name="google" content="notranslate">
<style>
body, textarea {
background: black;
color: white;
}
textarea {
width: 100%;
height: 50%;
}
</style>
<script src="https://unpkg.com/peggy"></script>
<script>
(async () => { //make all the js async
window.onload = async () => {
let parse = () => {
console.log(JSON.stringify(window.parser.parse(document.getElementById("toparse").value), null, 2))
}
let update_parser = () =>
fetch('./js/anydice_grammar.peggy')
.then(response => response.text())
.then(grammar => {
window.parser = peggy.generate(grammar, {trace: false})
parse()
})
update_parser()
let toparse = document.getElementById("toparse")
toparse.value = window.localStorage.getItem("anydicescript")
toparse.onkeyup = (event) => {
clearTimeout(window.parseTimeout)
window.parseTimeout = setTimeout(parse, 500)
window.localStorage.setItem("anydicescript", event.target.value)
}
}})()
</script>
<script>
document.write(
'<script src="http://' +
(location.host || '${1:localhost}').split(':')[0] +
':${2:35729}/livereload.js?snipver=1"></' +
'script>'
);
</script>
</head>
<body>
<textarea id="toparse"></textarea>
</body>
</html>