| 1 | <!DOCTYPE html> |
|---|
| 2 | <html> |
|---|
| 3 | <head> |
|---|
| 4 | <script src="http://localhost:8000/static/TCPSocket.js"></script> |
|---|
| 5 | <script src="IRC.js"></script> |
|---|
| 6 | <script> |
|---|
| 7 | var hostname = "irc.freenode.net" |
|---|
| 8 | var channel = "#orbited.tutorial" |
|---|
| 9 | var port = 6667 |
|---|
| 10 | nickname = "" |
|---|
| 11 | |
|---|
| 12 | var client = new IRCClient() |
|---|
| 13 | |
|---|
| 14 | client.onopen = function() { |
|---|
| 15 | nickname = prompt("Please enter a user name") |
|---|
| 16 | client.nick(nickname) |
|---|
| 17 | client.ident(nickname, "8 *", "Tutorial User") |
|---|
| 18 | client.join(channel) |
|---|
| 19 | } |
|---|
| 20 | client.onnickInUse = function() { |
|---|
| 21 | nickname = prompt("That name was taken. Please try another") |
|---|
| 22 | client.nick(nickname) |
|---|
| 23 | client.ident(nickname, "8 *", "Tutorial User") |
|---|
| 24 | client.join(channel) |
|---|
| 25 | } |
|---|
| 26 | client.onmessage = function(sender, place, msg) { |
|---|
| 27 | if (place == channel) { |
|---|
| 28 | var nick = sender.slice(0, sender.search("!")) |
|---|
| 29 | print_output(nick + ": " + msg) |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | var print_output = function(s) { |
|---|
| 34 | var output = document.getElementById("output") |
|---|
| 35 | |
|---|
| 36 | // make output HTML safe |
|---|
| 37 | s = s.replace("&", "&", "g") |
|---|
| 38 | s = s.replace("<", "<", "g") |
|---|
| 39 | s = s.replace(">", ">", "g") |
|---|
| 40 | s = s.replace(" ", " ", "g") |
|---|
| 41 | |
|---|
| 42 | output.innerHTML += s + "<br>" |
|---|
| 43 | output.scrollTop = output.scrollHeight |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | var send_message = function() { |
|---|
| 47 | var input = document.getElementById("input") |
|---|
| 48 | print_output(nickname + ": " + input.value) |
|---|
| 49 | client.privmsg(channel, input.value) |
|---|
| 50 | } |
|---|
| 51 | </script> |
|---|
| 52 | </head> |
|---|
| 53 | <body> |
|---|
| 54 | <div id="output"></div> |
|---|
| 55 | <input type=text id="input"><button onclick="send_message()">Send</button> |
|---|
| 56 | <button onclick="client.connect(hostname,port)">Connect</button> |
|---|
| 57 | </body> |
|---|
| 58 | </html> |
|---|