PubNub
by BinaryAcid
HTML
Enter Chat and press enter
<div><input id=input placeholder=you-chat-here /></div>
Chat Output
<div id=box></div>
<div id=pubnub pub-key=demo sub-key=demo></div>
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script>
JavaScript
<h1>RegExRacer</h1>
(function(){
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chat';
PUBNUB.subscribe({
channel : channel,
callback : function(text) {
// checks answer and announces to all players a winner.
if(text == "dumbo"){
alert("I win!");
}
// box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML;
}
});
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
channel : channel, message : input.value, x : (input.value='')
});
});
})();