From 60c699bae44baf8342206df699c004da882fbb8f Mon Sep 17 00:00:00 2001 From: Michael Murtaugh Date: Mon, 8 Oct 2018 15:26:25 +0200 Subject: [PATCH] html + opts --- eliza.html | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ eliza.js | 14 +++++++++--- 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 eliza.html diff --git a/eliza.html b/eliza.html new file mode 100644 index 0000000..7877090 --- /dev/null +++ b/eliza.html @@ -0,0 +1,66 @@ + + + + + + + + +
+
+
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/eliza.js b/eliza.js index fd9cf5d..b8a5bcb 100644 --- a/eliza.js +++ b/eliza.js @@ -7,7 +7,12 @@ See LICENSE.txt and http://artlibre.org/licence/lal/en/ Use the accompanying eliza_script_to_json.py to prepare the rules in JSON format */ -function chatbot (rules, textarea, display, debug) { +function chatbot (opts) { + var rules = opts.rules, + textarea = opts.input, + display = opts.output, + debug = opts.debug || false, + autoscroll = opts.autoscroll === undefined ? true : opts.autoscroll; var saved_statements = []; function process_rules (rules) { function looping_iterator (l) { @@ -153,7 +158,7 @@ function chatbot (rules, textarea, display, debug) { var keyword = keywords[i]; if ((keyword.token == "xnone") && (saved_statements.length > 0)) { console.log("using saved statement"); - return saved_statements.pop(); + return saved_statements.shift(); } while (true) { console.log("trying keyword", keyword.token); @@ -183,13 +188,16 @@ function chatbot (rules, textarea, display, debug) { function log (msg, kls) { var d = document.createElement("div"); - d.setAttribute("class", kls); + d.setAttribute("class", "msg " + kls); d.innerHTML = msg; display.appendChild(d); } function say (msg) { log(msg, "bot"); + if (autoscroll) { + display.scrollTop = display.scrollTopMax; + } } function process (text) {