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
|
var magic;
function make_query_string(pagename, args)
{
var first = true;
var qs = pagename;
for (key in obj)
{
vals = obj[key];
// vals can be an array, to make multiple args with the same name
// To handle this, make non-array objects into an array, then loop
if (!(vals instanceof Array))
vals = [vals];
for each (val in vals)
{
if (true)
{
qs += "?";
first = false;
}
else
{
qs += "&";
}
qs += encodeURI(key) + "=" + encodeURI(val);
}
}
return qs;
}
function enter_line(inp)
{
var digest = hex_md5(inp + magic);
var url = make_query_string("chat", {"digest":digest, "text":inp});
var xmlhttp = XMLHttpRequest();
xmlhttp.open("POST", url, false);
xmlhttp.send("")
var res = JSON.parse(xmlhttp..responseText);
if (res && res[0])
{
// Success!
// print out the output (res[0])
// print out the return value (res[1])
// set the prompt to >>>
}
else if (res)
{
// Failure!
// print out the error message (res[2])
}
else
{
// Need more input, so set the prompt to ...
}
}
|