This commit is contained in:
Dan Seripap 2016-01-08 16:51:07 -05:00
parent 28ea129c10
commit 1838304893
3 changed files with 24 additions and 6 deletions

View File

@ -14,9 +14,13 @@ $(function() {
var $usernameInput = $('.usernameInput'); // Input for username
var $messages = $('.messages'); // Messages area
var $inputMessage = $('.inputMessage'); // Input message input box
var $key = $('#key');
var $chatPage = $('.chat.page'); // The chatroom page
var key = CryptoJS.SHA3(Math.random().toString(36).substring(7)).toString();
$key.val(key);
// Prompt for setting a username
var username;
var connected = false;
@ -49,7 +53,7 @@ $(function() {
} else {
fs(window.TEMPORARY,
100,
log.bind(log, "!!WARNING!! : Your browser is not in incognito mode! : !!WARNING!!"),
log.bind(log, "WARNING: Your browser is not in incognito mode!"),
log.bind(log, "Your browser is in incognito mode."));
}
@ -81,11 +85,11 @@ $(function() {
}
function encrypt(text) {
return CryptoJS.AES.encrypt(text, roomId).toString();
return CryptoJS.AES.encrypt(text, $key.val()).toString();
}
function decrypt(text) {
return CryptoJS.AES.decrypt(text, roomId).toString(CryptoJS.enc.Utf8);
return CryptoJS.AES.decrypt(text, $key.val()).toString(CryptoJS.enc.Utf8) || text;
}
// Log a message
@ -161,7 +165,9 @@ $(function() {
} else {
$messages.append($el);
}
$messages[0].scrollTop = $messages[0].scrollHeight;
$messages[0].scrollTop = $messages[0].scrollHeight; // minus 60 for key
console.log($messages[0]);
}
// Prevents input from having injected markup

View File

@ -98,7 +98,7 @@ ul {
font-size: 150%;
}
.inputMessage {
.inputMessage, #key {
font-size: 100%;
}
@ -137,7 +137,7 @@ ul {
/* Input */
.inputMessage {
.inputMessage{
border: 10px solid #000;
bottom: 0;
height: 60px;
@ -148,3 +148,13 @@ ul {
right: 0;
width: 100%;
}
#key {
border: 10px solid #000;
height: 60px;
left: 0;
outline: none;
padding-left: 10px;
right: 0;
width: 100%;
}

View File

@ -12,6 +12,7 @@
<ul class="pages">
<li class="chat page">
<div class="chatArea">
<input id="key" placeholder="Chat Key">
<ul class="messages"></ul>
</div>
<input class="inputMessage" placeholder="Type here..."/>
@ -20,6 +21,7 @@
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="https://cdn.socket.io/socket.io-1.4.3.js"></script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha3.js"></script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="/main.js"></script>
<script>