-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_test.html
87 lines (78 loc) · 2.44 KB
/
cmd_test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<script src="js/console.js"></script>
<script>
cmdkeydwon = function() {
setTimeout("document.getElementById(\"tx\").scrollIntoView(false);", 100);
}
cmd = new ConsoleForUser(cmdkeydwon, "@ ");
</script>
</head>
<body>
<pre>
<div rows="40" id="tx" style="width: 95% ; font-size: 16pt; padding: 0.5cm; font-family: 'Courier New', Courier, monospace;"></div>
</pre>
<textarea id="face" style="z-index: 10; top:0%; left: 0%; position: fixed; width: 100%; height: 1000%; opacity: 0.1;"></textarea>
<script>
document.body.onkeydown = function(e) {
var event = e || event || window.event;
// event.preventDefault();
// event.returnValue = false;
cmd.input(event.keyCode, event);
// cmd.shift_test_down(event.keyCode);
};
document.body.onkeyup = function() {
// event.preventDefault();
// event.returnValue = false;
// cmd.shift_test_up(event.keyCode);
};
document.getElementById("face").onkeydown = function() {
if (!window.OnKey) {
window.OnKey = function() {
var a = document.getElementById("face").value;
document.getElementById("face").value = "";
cmd.get_in(a);
};
setInterval(window.OnKey, 30);
}
// document.body.onkeydown = function() {}
// document.body.onkeyup = function() {}
};
cmd.help_string += "\nDemo help:\n\
echo \"<string>\" \tprint message on console.\n\
run \"[code]\" \trun js code in this page.\n\
alert \"<string>\" \talert message use browser alert components.\n\
help \tshow help doc.\n";
bin.echo = function(cf, cmds) {
for (var i = 1; i < cmds.length; i++) {
cf.print(cmds[i] + "", true);
}
return true;
};
bin.run = function(cf, cmds) {
for (var i = 1; i < cmds.length; i++) {
try {
cf.print(eval(cmds[i]) || "[Empty returned]");
} catch (e) {
cf.print(e.toString() + " /At/ " + cmds[i]);
return "(x)";
}
}
return true;
};
bin.alert = function(cf, cmds) {
for (var i = 1; i < cmds.length; i++) {
alert(cmds[i]);
}
return true;
}
function update() {
document.getElementById("tx").innerHTML = cmd.toShow();
}
setInterval(update, 10);
cmd.start();
document.getElementById("face").focus();
</script>
</body>
</html>