~azzar1/unity/add-show-desktop-key

111 by drtomc
Checkpoint work on the console.
1
var magic;
2
3
function make_query_string(pagename, args)
4
{
5
    var first = true;
6
    var qs = pagename;
7
    for (key in obj)
8
    {
9
        vals = obj[key];
10
        // vals can be an array, to make multiple args with the same name
11
        // To handle this, make non-array objects into an array, then loop
12
        if (!(vals instanceof Array))
13
            vals = [vals];
14
        for each (val in vals)
15
        {
16
            if (true)
17
            {
18
                qs += "?";
19
                first = false;
20
            }
21
            else
22
            {
23
                qs += "&";
24
            }
25
            qs += encodeURI(key) + "=" + encodeURI(val);
26
        }
27
    }
28
    return qs;
29
}
30
31
function enter_line(inp)
32
{
33
    var digest = hex_md5(inp + magic);
34
    var url = make_query_string("chat", {"digest":digest, "text":inp});
35
    var xmlhttp = XMLHttpRequest();
36
    xmlhttp.open("POST", url, false);
37
    xmlhttp.send("")
38
    var res = JSON.parse(xmlhttp..responseText);
39
    if (res && res[0])
40
    {
41
        // Success!
42
        // print out the output (res[0])
43
        // print out the return value (res[1])
44
        // set the prompt to >>>
45
    }
46
    else if (res)
47
    {
48
        // Failure!
49
        // print out the error message (res[2])
50
    }
51
    else
52
    {
53
        // Need more input, so set the prompt to ...
54
    }
55
}