72
72
var hist = new History();
74
function make_query_string(pagename, args)
81
// vals can be an array, to make multiple args with the same name
82
// To handle this, make non-array objects into an array, then loop
83
if (!(vals instanceof Array))
85
for each (val in vals)
96
qs += encodeURI(key) + "=" + encodeURI(val);
102
74
function make_post_body(args)
131
99
var inp = document.getElementById('inputText');
132
100
var digest = hex_md5(inp.value + magic);
133
101
var xmlhttp = new XMLHttpRequest();
135
102
xmlhttp.open("POST", "chat", false);
136
103
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
137
104
xmlhttp.send(make_post_body({"digest":digest, "text":inp.value}))
138
105
var res = JSON.parse(xmlhttp.responseText);
139
var output = document.getElementById("output")
106
var output = document.getElementById("output");
141
108
var pre = document.createElement("pre");
142
109
pre.setAttribute("class", "inputMsg");
143
110
pre.appendChild(document.createTextNode(inp.value + "\n"));
144
111
output.appendChild(pre);
113
if (res.hasOwnProperty('okay'))
149
// print out the output (res[0])
116
// print out the output (res.okay[0])
150
117
var pre = document.createElement("pre");
151
118
pre.setAttribute("class", "outputMsg");
152
pre.appendChild(document.createTextNode(res[0]));
119
pre.appendChild(document.createTextNode(res.okay[0]));
153
120
output.appendChild(pre);
154
// print out the return value (res[1])
121
// print out the return value (res.okay[1])
157
124
var pre = document.createElement("pre");
158
125
pre.setAttribute("class", "outputMsg");
159
pre.appendChild(document.createTextNode(res[1] + "\n"));
126
pre.appendChild(document.createTextNode(res.okay[1] + "\n"));
160
127
output.appendChild(pre);
162
129
// set the prompt to >>>
163
130
var prompt = document.getElementById("prompt");
164
131
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
133
else if (res.hasOwnProperty('exc'))
169
// print out the error message (res[2])
136
// print out the error message (res.exc)
170
137
var pre = document.createElement("pre");
171
138
pre.setAttribute("class", "errorMsg");
172
pre.appendChild(document.createTextNode(res[2]));
139
pre.appendChild(document.createTextNode(res.exc));
173
140
output.appendChild(pre);
142
else if (res.hasOwnProperty('more'))
177
144
// Need more input, so set the prompt to ...
178
145
var prompt = document.getElementById("prompt");
179
146
prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
149
// assert res.hasOwnProperty('input')
150
var prompt = document.getElementById("prompt");
151
prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
183
155
function catch_input(key)