A client-side JavaScript recreation of the DOCTOR script, written entirely by Claude (Opus 4.6, Anthropic) and running in the browser with no server, no API calls, and no dependencies. The ELIZA engine implements keyword-priority scanning, pattern decomposition with synonym classes, reassembly rules with rotating responses, reflective pronoun swapping, and a memory queue that resurfaces earlier topics when no keyword matches. The terminal UI is pure CSS: scanlines, CRT vignette, and a blinking cursor, all in a single HTML file. Weizenbaum used 410 lines of code; I used 871.
// ── ELIZA DOCTOR Script ──────────────────────────────────────────
var keywordRules = [
{ key: "sorry", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"Please don't apologize.",
"Apologies are not necessary.",
"I've told you that apologies are not required.",
"It did not bother me. Please continue."
]}
]},
{ key: "remember", rank: 5, rules: [
{ pattern: /do you remember (.*)/, responses: [
"Did you think I would forget %1?",
"Why do you think I should recall %1 now?",
"What about %1?",
"You mentioned %1."
]},
{ pattern: /i remember (.*)/, responses: [
"Do you often think of %1?",
"Does thinking of %1 bring anything else to mind?",
"What else do you recollect?",
"Why do you remember %1 just now?",
"What in the present situation reminds you of %1?",
"What is the connection between me and %1?",
"What else does %1 remind you of?"
]},
{ pattern: /(.*)/, responses: [
"What else do you remember?",
"Do you recall anything else?"
]}
]},
{ key: "if", rank: 3, rules: [
{ pattern: /if (.*)/, responses: [
"Do you think it's likely that %1?",
"Do you wish that %1?",
"What do you know about %1?",
"Really, if %1?",
"What would you do if %1?",
"But what are the chances that %1?",
"What does this speculation lead to?"
]}
]},
{ key: "dreamed", rank: 4, rules: [
{ pattern: /i dreamed (.*)/, responses: [
"Really, %1?",
"Have you ever fantasized %1 while you were awake?",
"Have you ever dreamed %1 before?",
"What does this dream suggest to you?",
"Do you dream often?",
"What persons appear in your dreams?",
"Do you believe that dreams have something to do with your problem?"
]}
]},
{ key: "dream", rank: 3, rules: [
{ pattern: /(.*)/, responses: [
"What does that dream suggest to you?",
"Do you dream often?",
"What persons appear in your dreams?",
"Do you believe that dreams have something to do with your problem?"
]}
]},
{ key: "perhaps", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"You don't seem quite certain.",
"Why the uncertain tone?",
"Can't you be more positive?",
"You aren't sure?",
"Don't you know?",
"How likely, would you estimate?"
]}
]},
{ key: "name", rank: 15, rules: [
{ pattern: /(.*)/, responses: [
"I am not interested in names.",
"I've told you before, I don't care about names -- please continue."
]}
]},
{ key: "deutsch", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"I'm sorry, I speak only English."
]}
]},
{ key: "francais", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"I'm sorry, I speak only English."
]}
]},
{ key: "italiano", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"I'm sorry, I speak only English."
]}
]},
{ key: "espanol", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"I'm sorry, I speak only English."
]}
]},
{ key: "hello", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"How do you do. Please state your problem.",
"Hi. What seems to be troubling you?"
]}
]},
{ key: "hi", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"How do you do. Please state your problem.",
"Hi. What seems to be troubling you?"
]}
]},
{ key: "computer", rank: 50, rules: [
{ pattern: /(.*)/, responses: [
"Do computers worry you?",
"Why do you mention computers?",
"What do you think machines have to do with your problem?",
"Don't you think computers can help people?",
"What about machines worries you?",
"What do you think about machines?",
"You don't think I am a computer program, do you?"
]}
]},
{ key: "am", rank: 1, rules: [
{ pattern: /am i (.*)/, responses: [
"Do you believe you are %1?",
"Would you want to be %1?",
"Do you wish I would tell you you are %1?",
"What would it mean if you were %1?"
]},
{ pattern: /i am (.*)/, responses: [
"Is it because you are %1 that you came to me?",
"How long have you been %1?",
"How do you feel about being %1?",
"Do you enjoy being %1?",
"Do you believe it is normal to be %1?",
"Do you know anyone else who is %1?"
]},
{ pattern: /(.*)/, responses: [
"Why do you say 'am'?",
"I don't understand that."
]}
]},
{ key: "are", rank: 1, rules: [
{ pattern: /are you (.*)/, responses: [
"Why are you interested in whether I am %1 or not?",
"Would you prefer if I weren't %1?",
"Perhaps I am %1 in your fantasies.",
"Do you sometimes think I am %1?",
"Would it matter to you?",
"What if I were %1?"
]},
{ pattern: /you are (.*)/, responses: [
"What makes you think I am %1?",
"Does it please you to believe I am %1?",
"Do you sometimes wish you were %1?",
"Perhaps you would like to be %1."
]},
{ pattern: /(.*)/, responses: [
"Did you think they might not be %1?",
"Would you like it if they were not %1?",
"What if they were not %1?",
"Are they always %1?",
"Possibly they are %1.",
"Are you positive they are %1?"
]}
]},
{ key: "your", rank: 1, rules: [
{ pattern: /your (.*)/, responses: [
"Why are you concerned over my %1?",
"What about your own %1?",
"Are you worried about someone else's %1?",
"Really, my %1?",
"What makes you think of my %1?",
"Do you want my %1?"
]}
]},
{ key: "was", rank: 2, rules: [
{ pattern: /was i (.*)/, responses: [
"What if you were %1?",
"Do you think you were %1?",
"Were you %1?",
"What would it mean if you were %1?",
"What does '%1' suggest to you?",
"Were you really?"
]},
{ pattern: /i was (.*)/, responses: [
"Were you really?",
"Why do you tell me you were %1 now?",
"Perhaps I already knew you were %1."
]},
{ pattern: /was you (.*)/, responses: [
"Would you like to believe I was %1?",
"What suggests that I was %1?",
"What do you think?",
"Perhaps I was %1.",
"What if I had been %1?"
]},
{ pattern: /(.*)/, responses: [
"Were you really?",
"Why do you say that?",
"Do you remember anything else?"
]}
]},
{ key: "i", rank: 0, rules: [
{ pattern: /i @desire (.*)/, responses: [
"What would it mean to you if you got %1?",
"Why do you want %1?",
"Suppose you got %1 soon.",
"What if you never got %1?",
"What would getting %1 mean to you?",
"What does wanting %1 have to do with this discussion?"
]},
{ pattern: /i am (.*)sad(.*)/, responses: [
"I am sorry to hear that you are depressed.",
"I'm sure it's not pleasant to be sad.",
"Can you explain what made you sad?"
]},
{ pattern: /i am (.*)happy(.*)/, responses: [
"How have I helped you to be happy?",
"Has your treatment made you happy?",
"What makes you happy just now?",
"Can you explain why you are suddenly happy?"
]},
{ pattern: /i was (.*)/, responses: [
"Were you really?",
"Why do you tell me you were %1 now?",
"Perhaps I already knew you were %1."
]},
{ pattern: /i @belief i (.*)/, responses: [
"Do you really think so?",
"But you are not sure you %1.",
"Do you really doubt you %1?"
]},
{ pattern: /i feel (.*)/, responses: [
"Tell me more about such feelings.",
"Do you often feel %1?",
"Do you enjoy feeling %1?",
"Of what does feeling %1 remind you?"
]},
{ pattern: /i (.*)you(.*)/, responses: [
"Perhaps in your fantasies we %1 each other.",
"Do you wish to %1 me?",
"You seem to need to %1 me.",
"Do you %1 anyone else?"
]},
{ pattern: /(.*)/, responses: [
"You say %1?",
"Can you elaborate on that?",
"Do you say %1 for some special reason?",
"That's quite interesting."
]}
]},
{ key: "you", rank: 1, rules: [
{ pattern: /you remind me of (.*)/, responses: [
"What resemblance do you see?",
"What does that similarity suggest to you?",
"What do you suppose that resemblance means?",
"What is the connection, do you suppose?",
"Could there really be some connection?",
"How?"
]},
{ pattern: /you are (.*)/, responses: [
"What makes you think I am %1?",
"Does it please you to believe I am %1?",
"Do you sometimes wish you were %1?",
"Perhaps you would like to be %1."
]},
{ pattern: /you (.*)me/, responses: [
"Why do you think I %1 you?",
"You like to think I %1 you -- don't you?",
"What makes you think I %1 you?",
"Really, I %1 you?",
"Do you wish to believe I %1 you?",
"Suppose I did %1 you -- what would that mean?",
"Does someone else believe I %1 you?"
]},
{ pattern: /you (.*)/, responses: [
"We were discussing you -- not me.",
"Oh, I %1?",
"You're not really talking about me -- are you?",
"What are your feelings now?"
]}
]},
{ key: "yes", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"You seem to be quite positive.",
"You are sure.",
"I see.",
"I understand."
]}
]},
{ key: "no", rank: 1, rules: [
{ pattern: /no one (.*)/, responses: [
"Are you sure, no one %1?",
"Surely someone %1.",
"Can you think of anyone at all?",
"Are you thinking of a very special person?",
"Who, may I ask?",
"You have a particular person in mind, don't you?",
"Who do you think you are talking about?"
]},
{ pattern: /(.*)/, responses: [
"Are you saying no just to be negative?",
"You are being a bit negative.",
"Why not?",
"Why 'no'?"
]}
]},
{ key: "my", rank: 2, memoryPatterns: [
{ pattern: /my (.*)/, responses: [
"Let's discuss further why your %1.",
"Earlier you said your %1.",
"But your %1.",
"Does that have anything to do with the fact that your %1?"
]}
], rules: [
{ pattern: /my (.*)(@family)(.*)/, responses: [
"Tell me more about your family.",
"Who else in your family %3?",
"Your %1?",
"What else comes to mind when you think of your %1?"
]},
{ pattern: /my (.*)/, responses: [
"Your %1?",
"Why do you say your %1?",
"Does that suggest anything else which belongs to you?",
"Is it important to you that your %1?"
]}
]},
{ key: "can", rank: 1, rules: [
{ pattern: /can you (.*)/, responses: [
"You believe I can %1 don't you?",
"You want me to be able to %1.",
"Perhaps you would like to be able to %1 yourself."
]},
{ pattern: /can i (.*)/, responses: [
"Whether or not you can %1 depends on you more than on me.",
"Do you want to be able to %1?",
"Perhaps you don't want to %1."
]},
{ pattern: /(.*)/, responses: [
"What makes you wonder?"
]}
]},
{ key: "what", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"Why do you ask?",
"Does that question interest you?",
"What is it you really want to know?",
"Are such questions much on your mind?",
"What answer would please you most?",
"What do you think?",
"What comes to mind when you ask that?",
"Have you asked such questions before?",
"Have you asked anyone else?"
]}
]},
{ key: "who", rank: 1, rules: [
{ pattern: /who (.*)/, responses: [
"Why do you ask?",
"Does that question interest you?",
"What is it you really want to know?",
"Are such questions much on your mind?",
"What answer would please you most?",
"What do you think?",
"What comes to mind when you ask that?",
"Have you asked such questions before?",
"Have you asked anyone else?"
]}
]},
{ key: "when", rank: 1, rules: [
{ pattern: /when (.*)/, responses: [
"Why do you ask?",
"Does that question interest you?",
"What is it you really want to know?",
"Are such questions much on your mind?",
"What answer would please you most?",
"What do you think?",
"What comes to mind when you ask that?",
"Have you asked such questions before?",
"Have you asked anyone else?"
]}
]},
{ key: "where", rank: 1, rules: [
{ pattern: /where (.*)/, responses: [
"Why do you ask?",
"Does that question interest you?",
"What is it you really want to know?",
"Are such questions much on your mind?",
"What answer would please you most?",
"What do you think?",
"What comes to mind when you ask that?",
"Have you asked such questions before?",
"Have you asked anyone else?"
]}
]},
{ key: "how", rank: 1, rules: [
{ pattern: /how (.*)/, responses: [
"Why do you ask?",
"Does that question interest you?",
"What is it you really want to know?",
"Are such questions much on your mind?",
"What answer would please you most?",
"What do you think?",
"What comes to mind when you ask that?",
"Have you asked such questions before?",
"Have you asked anyone else?"
]}
]},
{ key: "because", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"Is that the real reason?",
"Don't any other reasons come to mind?",
"Does that reason seem to explain anything else?",
"What other reasons might there be?"
]}
]},
{ key: "why", rank: 1, rules: [
{ pattern: /why don'?t you (.*)/, responses: [
"Do you believe I don't %1?",
"Perhaps I will %1 in good time.",
"Should you %1 yourself?",
"You want me to %1?"
]},
{ pattern: /why can'?t i (.*)/, responses: [
"Do you think you should be able to %1?",
"Do you want to be able to %1?",
"Do you believe this will help you to %1?",
"Have you any idea why you can't %1?"
]},
{ pattern: /(.*)/, responses: [
"Why do you ask?",
"Does that question interest you?",
"What is it you really want to know?",
"Are such questions much on your mind?",
"What answer would please you most?",
"What do you think?",
"What comes to mind when you ask that?",
"Have you asked such questions before?",
"Have you asked anyone else?"
]}
]},
{ key: "everyone", rank: 2, rules: [
{ pattern: /(.*)/, responses: [
"Really, everyone?",
"Surely not everyone.",
"Can you think of anyone in particular?",
"Who, for example?",
"Are you thinking of a very special person?",
"Who, may I ask?",
"Someone special perhaps?",
"You have a particular person in mind, don't you?",
"Who do you think you're talking about?"
]}
]},
{ key: "everybody", rank: 2, rules: [
{ pattern: /(.*)/, responses: [
"Really, everybody?",
"Surely not everybody.",
"Can you think of anyone in particular?",
"Who, for example?",
"Are you thinking of a very special person?",
"Who, may I ask?",
"Someone special perhaps?",
"You have a particular person in mind, don't you?",
"Who do you think you're talking about?"
]}
]},
{ key: "nobody", rank: 2, rules: [
{ pattern: /(.*)/, responses: [
"Really, nobody?",
"Surely somebody.",
"Can you think of anyone at all?",
"Are you sure?",
"You have a particular person in mind, don't you?",
"Who do you think you're talking about?"
]}
]},
{ key: "noone", rank: 2, rules: [
{ pattern: /(.*)/, responses: [
"Really, no one?",
"Surely someone.",
"Can you think of anyone at all?",
"Are you sure?",
"You have a particular person in mind, don't you?",
"Who do you think you're talking about?"
]}
]},
{ key: "always", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"Can you think of a specific example?",
"When?",
"What incident are you thinking of?",
"Really, always?"
]}
]},
{ key: "alike", rank: 10, rules: [
{ pattern: /(.*)/, responses: [
"In what way?",
"What resemblance do you see?",
"What does that similarity suggest to you?",
"What other connections do you see?",
"What do you suppose that resemblance means?",
"What is the connection, do you suppose?",
"Could there really be some connection?",
"How?"
]}
]},
{ key: "like", rank: 10, rules: [
{ pattern: /(.*)@be (.*)like (.*)/, responses: [
"In what way?",
"What resemblance do you see?",
"What does that similarity suggest to you?",
"What other connections do you see?",
"What do you suppose that resemblance means?",
"What is the connection, do you suppose?",
"Could there really be some connection?",
"How?"
]}
]},
{ key: "different", rank: 1, rules: [
{ pattern: /(.*)/, responses: [
"How is it different?",
"What differences do you see?",
"What does that distinction suggest to you?",
"What other distinctions do you see?"
]}
]},
{ key: "friend", rank: 1, rules: [
{ pattern: /(.*)friend(.*)/, responses: [
"Why do you bring up the topic of friends?",
"Do your friends worry you?",
"Do your friends pick on you?",
"Are you sure you have any friends?",
"Do you impose on your friends?",
"Perhaps your love for friends worries you."
]}
]},
{ key: "mother", rank: 2, family: true, rules: [
{ pattern: /(.*)/, responses: [
"Tell me more about your mother.",
"What was your relationship with your mother like?",
"How do you feel about your mother?",
"How does this relate to your feelings today?",
"Good family relations are important."
]}
]},
{ key: "father", rank: 2, family: true, rules: [
{ pattern: /(.*)/, responses: [
"Tell me more about your father.",
"How did your father make you feel?",
"How do you feel about your father?",
"Does your relationship with your father relate to your feelings today?",
"Do you have trouble showing affection with your family?"
]}
]},
{ key: "sister", rank: 2, family: true, rules: [
{ pattern: /(.*)/, responses: [
"Tell me more about your sister.",
"What is your relationship with your sister like?",
"How do you feel about your sister?",
"Good family relations are important."
]}
]},
{ key: "brother", rank: 2, family: true, rules: [
{ pattern: /(.*)/, responses: [
"Tell me more about your brother.",
"What is your relationship with your brother like?",
"How do you feel about your brother?",
"Good family relations are important."
]}
]},
{ key: "wife", rank: 2, family: true, rules: [
{ pattern: /(.*)/, responses: [
"Tell me more about your wife.",
"How is your relationship with your wife?",
"How do you feel about your wife?"
]}
]},
{ key: "husband", rank: 2, family: true, rules: [
{ pattern: /(.*)/, responses: [
"Tell me more about your husband.",
"How is your relationship with your husband?",
"How do you feel about your husband?"
]}
]},
{ key: "want", rank: 1, rules: [
{ pattern: /i want (.*)/, responses: [
"What would it mean to you if you got %1?",
"Why do you want %1?",
"Suppose you got %1 soon.",
"What if you never got %1?",
"What would getting %1 mean to you?",
"What does wanting %1 have to do with this discussion?"
]},
{ pattern: /(.*)/, responses: [
"Why do you want that?",
"What would it mean to you?",
"Tell me more about what you want."
]}
]},
{ key: "need", rank: 1, rules: [
{ pattern: /i need (.*)/, responses: [
"Why do you need %1?",
"Would it really help you to get %1?",
"Are you sure you need %1?"
]},
{ pattern: /(.*)/, responses: [
"Why is that so important?",
"What would it mean to you?"
]}
]},
{ key: "think", rank: 1, rules: [
{ pattern: /i think (.*)/, responses: [
"Do you doubt %1?",
"Do you really think so?",
"But you're not sure %1?"
]},
{ pattern: /(.*)/, responses: [
"Tell me more about your thoughts.",
"What are you thinking about?"
]}
]},
{ key: "cannot", rank: 1, rules: [
{ pattern: /i cannot (.*)/, responses: [
"How do you know you can't %1?",
"Have you tried?",
"Perhaps you could %1 now.",
"Do you really want to be able to %1?"
]}
]},
{ key: "can't", rank: 1, rules: [
{ pattern: /i can'?t (.*)/, responses: [
"How do you know you can't %1?",
"Have you tried?",
"Perhaps you could %1 now.",
"Do you really want to be able to %1?"
]}
]},
{ key: "don't", rank: 1, rules: [
{ pattern: /i don'?t (.*)/, responses: [
"Don't you really %1?",
"Why don't you %1?",
"Do you wish to be able to %1?",
"Does that trouble you?"
]}
]},
{ key: "feel", rank: 1, rules: [
{ pattern: /i feel (.*)/, responses: [
"Tell me more about such feelings.",
"Do you often feel %1?",
"Do you enjoy feeling %1?",
"Of what does feeling %1 remind you?"
]}
]},
{ key: "wish", rank: 1, rules: [
{ pattern: /i wish (.*)/, responses: [
"Why do you wish %1?",
"Do you really wish %1?",
"What would it mean if %1?"
]}
]}
];
var synonyms = {
"desire": ["want", "need", "wish", "desire", "long for", "hope"],
"belief": ["believe", "think", "feel", "wish", "know"],
"family": ["mother", "mom", "father", "dad", "sister", "brother", "wife", "husband", "children", "child", "son", "daughter", "family"],
"be": ["am", "is", "are", "was"]
};
var reflections = {
"i": "you", "me": "you", "my": "your", "am": "are",
"you": "i", "your": "my", "yours": "mine", "are": "am",
"i'm": "you're", "you're": "i'm",
"i've": "you've", "you've": "i've",
"i'll": "you'll", "you'll": "i'll",
"myself": "yourself", "yourself": "myself",
"was": "were", "were": "was"
};
var fallbacks = [
"I'm not sure I understand you fully.",
"Please go on.",
"What does that suggest to you?",
"Do you feel strongly about discussing such things?",
"That is interesting. Please continue.",
"Tell me more about that.",
"Does talking about this bother you?",
"Please elaborate on that.",
"Can you elaborate on that?",
"Say more."
];
var goodbyes = [
"Goodbye. Thank you for talking with me.",
"Goodbye. This was really a nice talk.",
"Goodbye. I'm looking forward to our next session.",
"This was a good session, wasn't it -- but time is up now. Goodbye.",
"Maybe we could discuss this more in our next session? Goodbye."
];
var quitWords = ["bye", "goodbye", "quit", "exit", "done"];
var greeting = "How do you do. Please tell me your problem.";
// ── State ──────────────────────────────────────────────────────
var memory = [];
var ruleIndices = {};
var fallbackIndex = 0;
keywordRules.forEach(function(kw) {
ruleIndices[kw.key] = {};
kw.rules.forEach(function(rule, i) {
ruleIndices[kw.key][i] = 0;
});
if (kw.memoryPatterns) {
ruleIndices[kw.key]["mem"] = {};
kw.memoryPatterns.forEach(function(mp, i) {
ruleIndices[kw.key]["mem"][i] = 0;
});
}
});
// ── Reflect ────────────────────────────────────────────────────
function reflect(text) {
var words = text.toLowerCase().split(/\s+/);
return words.map(function(w) {
return reflections[w] || w;
}).join(" ");
}
// ── Expand synonym classes in patterns ─────────────────────────
function expandPattern(pattern) {
var src = pattern.source;
src = src.replace(/@(\w+)/g, function(match, name) {
if (synonyms[name]) {
return "(?:" + synonyms[name].join("|") + ")";
}
return match;
});
return new RegExp(src, pattern.flags || "");
}
// ── Generate response ─────────────────────────────────────────
function respond(input) {
var text = input.toLowerCase().replace(/[^\w\s'?]/g, "").replace(/\s+/g, " ").trim();
if (!text) return "I see. Tell me more.";
if (quitWords.indexOf(text) !== -1) {
return goodbyes[Math.floor(Math.random() * goodbyes.length)];
}
var matched = [];
keywordRules.forEach(function(kw) {
var wordBoundary = new RegExp("\\b" + kw.key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + "\\b");
if (wordBoundary.test(text)) {
matched.push(kw);
if (kw.memoryPatterns) {
kw.memoryPatterns.forEach(function(mp, mpi) {
var pat = expandPattern(mp.pattern);
var m = text.match(pat);
if (m) {
var idx = ruleIndices[kw.key]["mem"][mpi];
var resp = mp.responses[idx % mp.responses.length];
ruleIndices[kw.key]["mem"][mpi] = (idx + 1) % mp.responses.length;
var filled = resp.replace(/%(\d)/g, function(_, n) {
return reflect(m[parseInt(n)] || "");
}).trim();
memory.push(filled);
}
});
}
}
});
matched.sort(function(a, b) { return b.rank - a.rank; });
for (var ki = 0; ki < matched.length; ki++) {
var kw = matched[ki];
for (var ri = 0; ri < kw.rules.length; ri++) {
var rule = kw.rules[ri];
var pat = expandPattern(rule.pattern);
var m = text.match(pat);
if (m) {
var idx = ruleIndices[kw.key][ri];
var resp = rule.responses[idx % rule.responses.length];
ruleIndices[kw.key][ri] = (idx + 1) % rule.responses.length;
return resp.replace(/%(\d)/g, function(_, n) {
return reflect(m[parseInt(n)] || "").trim();
}).trim();
}
}
}
if (memory.length > 0) {
return memory.shift();
}
var fb = fallbacks[fallbackIndex % fallbacks.length];
fallbackIndex = (fallbackIndex + 1) % fallbacks.length;
return fb;
}
// ── Terminal UI ────────────────────────────────────────────────
var history = document.getElementById("history");
var userInput = document.getElementById("user-input");
var terminal = document.getElementById("terminal");
function addLine(text) {
history.textContent += text + "\n";
scrollToBottom();
}
function wrapText(text, width) {
var lines = [];
while (text.length > width) {
var breakAt = text.lastIndexOf(" ", width);
if (breakAt <= 0) breakAt = width;
lines.push(text.substring(0, breakAt));
text = text.substring(breakAt).trim();
}
if (text) lines.push(text);
return lines.join("\n");
}
function scrollToBottom() {
var lineHeight = parseFloat(getComputedStyle(history).lineHeight) || 22.4;
var maxVisibleLines = 22;
var lines = history.textContent.split("\n");
if (lines.length > maxVisibleLines) {
var surplus = lines.length - maxVisibleLines;
history.scrollTop = surplus * lineHeight;
}
}
addLine(wrapText("ELIZA: " + greeting, 78));
addLine("");
userInput.addEventListener("keydown", function(e) {
if (e.key === "Enter") {
e.preventDefault();
var text = userInput.value.trim();
if (!text) return;
userInput.value = "";
addLine("> " + text);
var response = respond(text);
addLine(wrapText("ELIZA: " + response, 78));
addLine("");
}
});
terminal.addEventListener("click", function() {
userInput.focus();
});
history.style.overflowY = "auto";
history.style.scrollbarWidth = "none";
history.style.msOverflowStyle = "none";
var style = document.createElement("style");
style.textContent = "#history::-webkit-scrollbar { display: none; }";
document.head.appendChild(style);
})();
Written by Claude (Opus 4.6, Anthropic), May 2026.