-
Notifications
You must be signed in to change notification settings - Fork 10
/
kitchensink.js
33 lines (27 loc) · 965 Bytes
/
kitchensink.js
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
const search = new URLSearchParams(window.location.search);
const runtime = search.get("runtime") || "mpy";
const start = new Date().getTime();
function setupRuntime() {
search.set("runtime", runtime);
document.write(`<script type="${runtime}" src="main.py" config="kitchensink.toml"></script>`)
}
function toggleRuntime() {
setSearchParameter("runtime", runtime == "mpy" ? "py" : "mpy");
}
function setSearchParameter(key, value) {
search.set(key, value)
window.location.search = search.toString();
}
function setupToggle() {
const toggle = document.createElement("a");
const name = runtime == "mpy" ? "MicroPython" : "Pyodide";
toggle.text = name;
toggle.style = "margin-left: 12px; cursor: pointer; color: blue;"
toggle.addEventListener("click", toggleRuntime)
document.getElementById("title").appendChild(toggle);
}
function startTime() {
return new Date().getTime() - start;
}
setupRuntime()
setupToggle()