]>
git.scottworley.com Git - reliable-chat/blob - webclient/rc.html
4d21bc449b5e49c97fc450729c5928385ff91adb
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[/*
><!--*/
13 font-family: monospace;
20 background-color: #eef;
21 padding: 5px 5px 5px 0px;
25 padding: 0px 0px 0px 5px;
35 padding: 0px 5px 55px 5px;
36 vertical-align: bottom
38 img { width: 1px; height: 1px; }
39 iframe { display: none }
40 #status span { margin-right: 10px; }
42 background-color: #f00;
44 border: 1px solid black;
50 background-color: #0f0;
52 border: 1px solid black;
58 <script type=
"text/javascript"><!--//--><![CDATA[/
/><!--
59 var servers = ['chkno.net', 'rc2.chkno.net', 'echto.net', 'the-wes.com', 'vibrantlogic.com'];
61 var session = Math.random();
65 var nick = localStorage.getItem("nick");
72 function rcsetnick(new_nick) {
73 localStorage.setItem("nick", new_nick);
76 function rcserverbase(server) {
77 // Add the default port if server doesn't contain a port number already
78 if (server.indexOf(":") == -1) {
79 return "http://" + server + ":21059";
81 return "http://" + server;
85 function rcchangeserverstatus(server, new_status) {
86 var statusbar = document.getElementById("status");
87 var spans = statusbar.getElementsByTagName("span");
88 for (var i in spans) {
89 if (spans[i].firstChild && 'data' in spans[i].firstChild && spans[i].firstChild.data == server) {
90 spans[i].setAttribute("class", new_status);
95 function rcaddmessagetohistory(message) {
96 var d = document.createElement("div");
97 d.appendChild(document.createTextNode(message));
98 var h = document.getElementById("history");
100 window.scrollTo(0, document.body.scrollHeight);
104 function make_seen_key(id, text) {
105 return id.replace(/@/g, "@@") + "_@_" + text.replace(/@/g, "@@");
108 function receiveMessage(server, time, id, text) {
109 var seen_key = make_seen_key(id, text);
110 if (!(seen_key in seen)) {
111 seen[seen_key] = true;
112 rcaddmessagetohistory(text);
113 for (var i in servers) {
114 rcchangeserverstatus(servers[i], "sad");
117 rcchangeserverstatus(server, "happy");
120 function receiveMessageEvent(event)
122 for (var i in servers) {
123 if (event.origin === rcserverbase(servers[i])) {
124 messages = JSON.parse(event.data);
125 for (var j in messages) {
126 if ('Time' in messages[j] &&
127 'ID' in messages[j] &&
128 'Text' in messages[j]) {
129 receiveMessage(servers[i], messages[j]['Time'], messages[j]['ID'], messages[j]['Text']);
136 function rcconnect() {
137 window.addEventListener("message", receiveMessageEvent, false);
138 for (var i in servers) {
139 // Create a hidden iframe for same-origin workaround
140 var iframe = document.createElement("iframe");
141 iframe.setAttribute("src", rcserverbase(servers[i]) + "/frame");
142 document.body.insertBefore(iframe, document.body.firstChild);
144 var status_indicator = document.createElement("span");
145 status_indicator.appendChild(document.createTextNode(servers[i]));
146 status_indicator.setAttribute("class", "sad");
147 document.getElementById("status").appendChild(status_indicator);
149 if (rcnick() == 'anonymous') {
150 rcaddmessagetohistory("-!- Set your nick with /nick");
154 function rcsend(d, message) {
155 var id = new Date().getTime() + "-" + session + "-" + Math.random();
156 seen[make_seen_key(id, message)] = true;
157 var path = "/speak" +
158 "?id=" + encodeURIComponent(id) +
159 "&text=" + encodeURIComponent(message);
160 for (var i in servers) {
161 var uri = rcserverbase(servers[i]) + path;
162 var img = document.createElement("img");
163 img.setAttribute("src", uri);
168 function rckeydown(event) {
169 if (event.keyCode == 13) {
170 var input = document.input.say.value;
171 document.input.say.value = "";
175 var re = /^\/nick (.*)/;
176 var match = re.exec(input);
178 message = "*** " + rcnick() + " is now known as " + match[1];
181 message = "<" + rcnick() + "> " + input;
186 var re = /^\/me (.*)/;
187 var match = re.exec(input);
188 var inputme = input.substring(4);
190 message = "* " + rcnick() + " " + inputme;
192 message = "<" + rcnick() + "> " + input;
195 // Remind people to set their nick
196 if (rcnick() == 'anonymous') {
197 rcaddmessagetohistory("-!- Set your nick with /nick");
201 var d = rcaddmessagetohistory(message);
209 <body onload=
"rcconnect()">
211 <div id=
"history"></div>
214 <form name=
"input" onsubmit=
"return false" autocomplete=
"off">
215 <input id=
"say" onkeydown=
"return rckeydown(event)" autocomplete=
"off" autofocus=
"autofocus"></input>
217 <div id=
"status"> </div>