]>
git.scottworley.com Git - reliable-chat/blob - webclient/rc.html
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 background-color: #293134;
15 font-family: monospace;
23 background-color: #293134;
24 padding: 5px 5px 5px 0px;
28 padding: 0px 0px 0px 5px;
35 background-color: #293134;
39 padding: 0px 5px 55px 5px;
40 vertical-align: bottom
42 img { width: 1px; height: 1px; }
43 iframe { display: none }
44 #status span { margin-right: 10px; }
46 background-color: #f00;
48 border: 1px solid black;
54 background-color: #0f0;
56 border: 1px solid black;
62 <script type=
"text/javascript"><!--//--><![CDATA[/
/><!--
63 var servers = ['chkno.net', 'rc2.chkno.net', 'echto.net', 'the-wes.com', 'vibrantlogic.com'];
65 var session = Math.random();
69 var nick = localStorage.getItem("nick");
76 function rcsetnick(new_nick) {
77 localStorage.setItem("nick", new_nick);
80 function rcserverbase(server) {
81 // Add the default port if server doesn't contain a port number already
82 if (server.indexOf(":") == -1) {
83 return "http://" + server + ":21059";
85 return "http://" + server;
89 function rcchangeserverstatus(server, new_status) {
90 var statusbar = document.getElementById("status");
91 var spans = statusbar.getElementsByTagName("span");
92 for (var i in spans) {
93 if (spans[i].firstChild && 'data' in spans[i].firstChild && spans[i].firstChild.data == server) {
94 spans[i].setAttribute("class", new_status);
99 function rcaddmessagetohistory(message) {
100 var d = document.createElement("div");
101 d.appendChild(document.createTextNode(message));
102 var h = document.getElementById("history");
104 window.scrollTo(0, document.body.scrollHeight);
108 function make_seen_key(id, text) {
109 return id.replace(/@/g, "@@") + "_@_" + text.replace(/@/g, "@@");
112 function receiveMessage(server, time, id, text) {
113 var seen_key = make_seen_key(id, text);
114 if (!(seen_key in seen)) {
115 seen[seen_key] = true;
116 rcaddmessagetohistory(text);
117 for (var i in servers) {
118 rcchangeserverstatus(servers[i], "sad");
121 rcchangeserverstatus(server, "happy");
124 function receiveMessageEvent(event)
126 for (var i in servers) {
127 if (event.origin === rcserverbase(servers[i])) {
128 messages = JSON.parse(event.data);
129 for (var j in messages) {
130 if ('Time' in messages[j] &&
131 'ID' in messages[j] &&
132 'Text' in messages[j]) {
133 receiveMessage(servers[i], messages[j]['Time'], messages[j]['ID'], messages[j]['Text']);
140 function rcconnect() {
141 window.addEventListener("message", receiveMessageEvent, false);
142 for (var i in servers) {
143 // Create a hidden iframe for same-origin workaround
144 var iframe = document.createElement("iframe");
145 iframe.setAttribute("src", rcserverbase(servers[i]) + "/frame");
146 document.body.insertBefore(iframe, document.body.firstChild);
148 var status_indicator = document.createElement("span");
149 status_indicator.appendChild(document.createTextNode(servers[i]));
150 status_indicator.setAttribute("class", "sad");
151 document.getElementById("status").appendChild(status_indicator);
153 if (rcnick() == 'anonymous') {
154 rcaddmessagetohistory("-!- Set your nick with /nick");
158 function rcsend(d, message) {
159 var id = new Date().getTime() + "-" + session + "-" + Math.random();
160 seen[make_seen_key(id, message)] = true;
161 var path = "/speak" +
162 "?id=" + encodeURIComponent(id) +
163 "&text=" + encodeURIComponent(message);
164 for (var i in servers) {
165 var uri = rcserverbase(servers[i]) + path;
166 var img = document.createElement("img");
167 img.setAttribute("src", uri);
172 function rckeydown(event) {
173 if (event.keyCode == 13) {
174 var input = document.input.say.value;
175 document.input.say.value = "";
179 var re = /^\/nick (.*)/;
180 var match = re.exec(input);
182 message = "*** " + rcnick() + " is now known as " + match[1];
185 message = "<" + rcnick() + "> " + input;
190 var re = /^\/me (.*)/;
191 var match = re.exec(input);
192 var inputme = input.substring(4);
194 message = "* " + rcnick() + " " + inputme;
196 message = "<" + rcnick() + "> " + input;
199 // Remind people to set their nick
200 if (rcnick() == 'anonymous') {
201 rcaddmessagetohistory("-!- Set your nick with /nick");
205 var d = rcaddmessagetohistory(message);
213 <body onload=
"rcconnect()">
215 <div id=
"history"></div>
218 <form name=
"input" onsubmit=
"return false" autocomplete=
"off">
219 <input id=
"say" onkeydown=
"return rckeydown(event)" autocomplete=
"off" autofocus=
"autofocus"></input>
221 <div id=
"status"> </div>