-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathmay.html
37 lines (36 loc) · 1.13 KB
/
may.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
<meta name=viewport content='initial-scale=1.0, minimum-scale=0.25'>
<title>console</title>
<button id=run title='Ctrl+Enter'>Run</button>
<button id=cancelBtn title=Esc>Cancel</button><br>
<textarea id=editor style='width: 100%; height: 300px; font-family: monospace;' spellcheck=false autocapitalize=none>may()
async function may() {
while (true) {
log('😘')
await sleep(100)
if (cancel) return
}
}</textarea><br>
<textarea id=debug style='width: 100%; height: 300px; font-family: monospace;' spellcheck=false autocapitalize=none></textarea>
<script>
run.onclick = function () {
debug.value = '';
cancel = false;
eval('(async function () {' + editor.value + '\n})()');
};
cancelBtn.onclick = () => cancel = true;
editor.onkeydown = function (event) {
const ENTER = 13, ESC = 27;
if (event.ctrlKey && event.keyCode == ENTER) {
run.onclick();
} else if (event.keyCode == ESC) {
cancelBtn.onclick();
}
};
function log(...s) {
debug.value += s.join(' ');
debug.scrollTo(0, debug.scrollHeight);
}
async function sleep(delay = 0) {
return new Promise(r => setTimeout(r, delay));
}
</script>