You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.8 KiB
HTML
85 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title></title>
|
|
<meta charset="utf-8">
|
|
<style type="text/css">
|
|
#wrapper {
|
|
display: flex;
|
|
flex-direction: column;
|
|
position: absolute;
|
|
left: 5%; top: 5%; right: 5%; bottom: 5%;
|
|
}
|
|
#textinput {
|
|
width: 100%;
|
|
border: none;
|
|
background: none;
|
|
}
|
|
#input {
|
|
padding: 2%;
|
|
flex: 0 1 auto;
|
|
background: aqua;
|
|
}
|
|
#display {
|
|
flex: 1 1 auto;
|
|
background: pink;
|
|
padding: 2%;
|
|
overflow: auto;
|
|
}
|
|
#display div.msg {
|
|
padding-bottom: 0.5em;
|
|
}
|
|
#display div.human {
|
|
color: black;
|
|
}
|
|
#display div.bot {
|
|
color: black;
|
|
text-transform: uppercase;
|
|
}
|
|
#display div.debug {
|
|
color: red;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="wrapper">
|
|
<div id="display">
|
|
</div>
|
|
<div id="input">
|
|
<input type="text" id="textinput" autofocus />
|
|
</div>
|
|
</div>
|
|
<script src="eliza.js"></script>
|
|
<script>
|
|
function eliza (rules) {
|
|
var input = document.getElementById("textinput"),
|
|
output = document.getElementById("display"),
|
|
bot = chatbot(rules, true);
|
|
|
|
function log (msg, kls) {
|
|
var d = document.createElement("div");
|
|
d.setAttribute("class", "msg " + kls);
|
|
d.innerHTML = msg;
|
|
display.appendChild(d);
|
|
}
|
|
|
|
function say (msg) {
|
|
log(msg, "bot");
|
|
display.scrollTop = display.scrollTopMax;
|
|
}
|
|
|
|
input.addEventListener("keypress", function (event) {
|
|
if (event.keyCode == 13) {
|
|
var text = input.value;
|
|
log(text, "user");
|
|
say(bot(text), "bot");
|
|
input.value = "";
|
|
input.focus();
|
|
}
|
|
});
|
|
say(rules.initial);
|
|
}
|
|
</script>
|
|
<script src="doctor.js"></script>
|
|
</body>
|
|
</html> |