]>
git.scottworley.com Git - reliable-chat/blob - webclient/rc.html
9097323a9b013c8b20262aa6dc30883b5e7d300c
1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml">
6 <title>Reliable Chat
</title>
7 <style type=
"text/css"><!--/*--><![CDATA[/*
><!--*/
8 html, body, #outer-table, #history { width: 99.9%; height: 100%; margin: 0; padding: 0 }
9 #status { background-color: #eef }
11 #history { vertical-align: bottom }
12 img { width: 1px; height: 1px; }
13 iframe { display: none }
14 #status span { margin-right: 2em }
16 background-color: #f00;
18 border: 1px solid black;
24 background-color: #0f0;
26 border: 1px solid black;
32 <script type=
"text/javascript"><!--//--><![CDATA[/
/><!--
33 var servers = ['chkno.net', 'rc2.chkno.net', 'echto.net', 'the-wes.com', 'vibrantlogic.com'];
35 var session = Math.random();
39 var nick = localStorage.getItem("nick");
46 function rcsetnick(new_nick) {
47 localStorage.setItem("nick", new_nick);
50 function rcserverbase(server) {
51 // Add the default port if server doesn't contain a port number already
52 if (server.indexOf(":") == -1) {
53 return "http://" + server + ":21059";
55 return "http://" + server;
59 function rcchangeserverstatus(server, new_status) {
60 var statusbar = document.getElementById("status");
61 var spans = statusbar.getElementsByTagName("span");
62 for (var i in spans) {
63 if (spans[i].firstChild && 'data' in spans[i].firstChild && spans[i].firstChild.data == server) {
64 spans[i].setAttribute("class", new_status);
69 function rcaddmessagetohistory(message) {
70 var d = document.createElement("div");
71 d.appendChild(document.createTextNode(message));
72 var h = document.getElementById("history");
74 window.scrollTo(0, document.body.scrollHeight);
78 function make_seen_key(id, text) {
79 return id.replace(/@/g, "@@") + "_@_" + text.replace(/@/g, "@@");
82 function receiveMessage(server, time, id, text) {
83 var seen_key = make_seen_key(id, text);
84 if (!(seen_key in seen)) {
85 seen[seen_key] = true;
86 rcaddmessagetohistory(text);
87 for (var i in servers) {
88 rcchangeserverstatus(servers[i], "sad");
91 rcchangeserverstatus(server, "happy");
94 function receiveMessageEvent(event)
96 for (var i in servers) {
97 if (event.origin === rcserverbase(servers[i])) {
98 messages = JSON.parse(event.data);
99 for (var j in messages) {
100 if ('Time' in messages[j] &&
101 'ID' in messages[j] &&
102 'Text' in messages[j]) {
103 receiveMessage(servers[i], messages[j]['Time'], messages[j]['ID'], messages[j]['Text']);
110 function rcconnect() {
111 window.addEventListener("message", receiveMessageEvent, false);
112 for (var i in servers) {
113 // Create a hidden iframe for same-origin workaround
114 var iframe = document.createElement("iframe");
115 iframe.setAttribute("src", rcserverbase(servers[i]) + "/frame");
116 document.body.insertBefore(iframe, document.body.firstChild);
118 var status_indicator = document.createElement("span");
119 status_indicator.appendChild(document.createTextNode(servers[i]));
120 status_indicator.setAttribute("class", "sad");
121 document.getElementById("status").appendChild(status_indicator);
123 if (rcnick() == 'anonymous') {
124 rcaddmessagetohistory("-!- Set your nick with /nick");
128 function rcsend(d, message) {
129 var id = new Date().getTime() + "-" + session + "-" + Math.random();
130 seen[make_seen_key(id, message)] = true;
131 var path = "/speak" +
132 "?id=" + encodeURIComponent(id) +
133 "&text=" + encodeURIComponent(message);
134 for (var i in servers) {
135 var uri = rcserverbase(servers[i]) + path;
136 var img = document.createElement("img");
137 img.setAttribute("src", uri);
142 function rckeydown(event) {
143 if (event.keyCode == 13) {
144 var input = document.input.say.value;
145 document.input.say.value = "";
149 var re = /^\/nick (.*)/;
150 var match = re.exec(input);
152 message = "*** " + rcnick() + " is now known as " + match[1];
155 message = "<" + rcnick() + "> " + input;
160 var re = /^\/me (.*)/;
161 var match = re.exec(input);
162 var inputme = input.substring(4);
164 message = "* " + rcnick() + " " + inputme;
166 message = "<" + rcnick() + "> " + input;
169 // Remind people to set their nick
170 if (rcnick() == 'anonymous') {
171 rcaddmessagetohistory("-!- Set your nick with /nick");
175 var d = rcaddmessagetohistory(message);
183 <body onload=
"rcconnect()">
184 <table id=
"outer-table">
185 <tr><td id=
"history"></td></tr>
186 <tr><td id=
"status"> </td></tr>
187 <tr><td><form name=
"input" onsubmit=
"return false" autocomplete=
"off">
188 <input id=
"say" onkeydown=
"return rckeydown(event)" autocomplete=
"off" autofocus=
"autofocus"></input>