forked from n8v/newfi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewfi.html
342 lines (271 loc) · 8.73 KB
/
newfi.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html>
<head>
<title>You don't meet the minimum requirements to have an opinion.</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="./newfi.css" />
<!--
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="http://www.zachstronaut.com/projects/winternetizer/winternetizer-combined-min.js" type="text/javascript"></script>
-->
<script type="text/javascript">
var last = 0;
var myname = 'noob';
var global_notificatable = false;
var moar=0;
// Let's write our own jQuery!
function getXMLRequest() {
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
return xmlhttp;
}
// http://www.html5rocks.com/en/tutorials/notifications/quick/
function notificator(who, blah) {
if (global_notificatable) {
console.log("notifigying " + myname + " that " + who + " said " + blah);
var lastNotice = window.webkitNotifications.createNotification(
null, who +' mentioned you in fi', blah).show();
}
}
function check_notificatable() {
if (global_notificatable) {
return true;
}
if (window.webkitNotifications) {
console.log("Notifications are supported!");
if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
return global_notificatable = true;
} else {
console.log("Requesting Notification Permission");
window.webkitNotifications.requestPermission();
// return check_notificatable();
}
}
else {
// console.log("Notifications are not supported for this Browser/OS version yet.");
return global_notificatable = false;
}
}
function add_line(txt)
{
var tbl = document.getElementById('pop');
// var t = document.createTextNode(txt);
var timestamp = '';
if (typeof(txt) === "string") {
var b = txt.split(': ');
if (b && b.length > 1) {
timestamp = b.shift();
var a = b.join(': ').split('> ');
} else {
var a = txt.split('> ');
}
}
var nick = a.shift();
var saying = a.join('> ');
var nickclass = nick == myname ? 'myself' : '';
var t = document.createElement('div');
t.className = 'saying';
t.innerHTML = '<span class="ts">' + timestamp +
': </span><span class="nick '+ nickclass +'">' +
nick + '> </span>' +
'<span class="blah">' + saying + '</span>';
if (nick != myname && saying && saying.length && saying.indexOf(myname) > -1) {
notificator(nick, saying);
}
// var it = row.insertCell(0);
tbl.appendChild(t);
}
function update() {
var xmlhttp = getXMLRequest();
if (!xmlhttp) {
setTimeout(update, 1000);
return;
}
xmlhttp.open("GET","./newfi.php?g=" + last,true);
xmlhttp.onerror = function() {
setTimeout(update, 1000);
return false;
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status!=200) {
change_name("FAIL!");
setTimeout(update, 1000);
return false;
}
var ret = xmlhttp.responseText;
setTimeout(update, 1000);
var semi = ret.indexOf(';');
if (semi > 0) {
last = 1 * ret.substring(0,semi);
var saystr = ret.substring(semi + 1);
var sayings = new Array();
sayings = saystr.split('\n');
var need_scroll = false;
for ( var i in sayings) {
//alert(sayings[i]);
if (sayings[i].length > 0) {
add_line(sayings[i]);
need_scroll = true;
}
}
if (need_scroll && !document.getElementById('scrolllock').checked ) {
// scroll to bottom
window.scrollTo(0, document.body.scrollHeight);
}
}
}
}
xmlhttp.setRequestHeader('Accept','text/html');
xmlhttp.send(null);
}
function runme() {
var cookies = document.cookie.split(';');
var nick = myname;
for(var i=0; i < cookies.length; i++) {
var c = cookies[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf('nick=') == 0) nick = c.substring(5,c.length);
}
document.getElementById('nick').value = nick;
myname = nick;
document.getElementById('saywut').value = '';
document.getElementById('saywut').focus();
update();
}
function go(e) {
valid=0;
check_notificatable();
if (e && e.which) {
e = e;
if (e.which != 13) return;
} else {
e = event;
if (e.keyCode != 13) return;
}
say();
return false;
}
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function say() {
var say;
if (moar) say = document.getElementById('saymoar').value;
else say = document.getElementById('saywut').value;
if (! say) {return false;}
var nick = document.getElementById('nick').value;
document.cookie = "nick=" + nick + "; expires= Tue Jan 19, 2038 03:14:07 UTC; path=/";
var spanclass = nick == myname ? 'myself' : '';
myname = nick;
say = say.replace(/\r\n|\n|\r/g, "<br />");
// emacs syntax is sad :<
var txt = encodeURIComponent(nick + "> " + say);
// encodeURIComponent(say);
var xmlhttp = getXMLRequest();
if (!xmlhttp) {
return;
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status!=200) {
change_name("FAIL!");
return false;
}
var ret = xmlhttp.responseText;
var semi = ret.indexOf(';');
if (semi > 0) {
last = 1 * ret.substring(0,semi);
var saystr = ret.substring(semi + 1);
var sayings = new Array();
sayings = saystr.split('\n');
for ( var i in sayings) {
if (sayings[i].length > 0) add_line(sayings[i]);
}
// scroll to bottom
if ( !document.getElementById('scrolllock').checked ) window.scrollTo(0, document.body.scrollHeight);
}
}
}
xmlhttp.open("POST","./newfi.php",true);
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send("s=" + txt);
document.getElementById('saywut').value = '';
document.getElementById('saymoar').value = '';
if (moar) document.getElementById('saymoar').focus();
else document.getElementById('saywut').focus();
return;
}
function swatch()
{
moar = 1 - moar;
if (moar == 0) {
document.getElementById('swatch').innerHTML = "moar";
document.getElementById('saywut').style.display = "inline";
document.getElementById('saymoar').style.display = "none";
} else {
document.getElementById('swatch').innerHTML = "less";
document.getElementById('saywut').style.display = "none";
document.getElementById('saymoar').style.display = "inline";
}
}
</script>
<!-- script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script -->
</head>
<body onload="runme()">
<div id=pop></div>
<hr>
<pre id=pre></pre>
<div style="width:100%">
<!-- form id="sayf" onsubmit="go(0); return false;" -->
<input type=text id=nick value="noob" onkeypress="go(event)" onblur="">
<input type=text id=saywut size=100 onkeypress="go(event)" onblur="say()">
<!--
<textarea id=say name=say width=100 height=1 onkeypress="go(event)" onblur="say()"></textarea>
-->
<textarea rows=1 cols=100 id=saymoar name=saymoar style="display: none;"></textarea>
<br>
<input type=submit onclick="say(); return false;" value="Say">
</form>
<button onclick="document.location.reload(true)">iPhone Button #2</button>
<button id=swatch onclick="swatch();">moar</button>
<input type=checkbox id=scrolllock name=scrolllock>SCROLL LOCK
</div>
</body>