This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nulchat.html
executable file
·101 lines (83 loc) · 2.67 KB
/
nulchat.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>nulchat</title>
<style type="text/css">
html, body {
background: #f3f3f3;
font-family: "Lucida Grande", Helvetica, Arial, sans-serif;
font-size: 15px;
}
input {
border: 1px solid #ccc;
border-radius:5px;
}
#text-input {width: 250px;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="/nowjs/now.js"></script>
<script>
function RequestPermission (callback)
{
if (!window.webkitNotifications) {
alert('Sorry, your browser does not support desktop notifications. Try Google Chrome.');
return;
}
if ($('#notify').attr('checked') && window.webkitNotifications.checkPermission() > 0) {
window.webkitNotifications.requestPermission();
}
}
function notify (chatMessage)
{
if (window.webkitNotifications.checkPermission() == 0) {
var icon = '';
var title = 'nulchat';
var body = chatMessage;
var popup = window.webkitNotifications.createNotification(icon, title, body);
popup.show();
setTimeout(function(){
popup.cancel();
}, '4000');
}
}
$(document).ready(function(){
now.name = prompt("What's your name?", "");
var myName = now.name;
now.receiveMessage = function(name, message){
$("#messages").append("<br>" + name + ": " + message);
if ($('#notify').attr('checked') && myName != name && window.webkitNotifications) {
notify(name + " says:" + message.substring(0,50));
}
}
$("#send-button").click(function(){
now.distributeMessage($("#text-input").val());
$("#text-input").val("");
});
$('#text-input').keypress(function(e){
if(e.which == 13){
now.distributeMessage($("#text-input").val());
$("#text-input").val("");
}
});
});
</script>
</head>
<body>
<div id="messages"></div>
<input type="text" id="text-input"/>
<input type="button" value="Send" id="send-button" /> <br/>
<input type="checkbox" id="notify" onclick="RequestPermission()" /> notify me (chrome only)
<br/>
<br/>
I've checked this example source into here...tweak it and I'll redeploy:
<br/>
<a href="https://github.com/jacobheric/nulchat" target="_blank">https://github.com/jacobheric/nulchat</a>
<br/>
<br/>
written with: <a href="http://nowjs.com/" target="_blank">http://nowjs.com/</a>
<br/>
runs on: <a href="http://nodejs.org/" target="_blank">http://nodejs.org/</a>
<br/>
<br/>
</body>
</html>