// Setup some varibles var profiles; var connections = []; var active_profile; var active_chat; // Load the profiles fs.readFile("profiles.json", "utf-8", function(err, data) { try { // Throw an error if there is one if(err) throw err; // Try to load it from the data profiles = JSON.parse(data); } catch(e) { // Set the profiles varible to its default value profiles = []; } // Reload the profiles profiles_reload(); // Connect to all the profiles for(var i=0;i" +connections[id].chats[i].name+""; } // Create a users menu var users_menu = ""; // Loop over the users var users_array = Object.keys(connections[id].users); for(var i=0;i"; } // Set the html data document.getElementById("chat-main").innerHTML = "\ \
\
\ \ "; // Set the title document.title = title(id); } function chat_switch_to(id) { // Create the chat html var chat_html = ""; // Setup some memory varibles var last_chat_user = ""; var last_chat_date = ""; // Loop over the messages for(var i=0;i "+date+"

"; } // Add some html data to the chat chat_html += "\
"+message_header+"\

"+text_to_html(connections[active_profile].chats[id].messages[i].message)+"

\
\ "; } // Set the HTML document.getElementById("chat-area").innerHTML = "\
"+chat_html+"
\
\ \ \
\ "; // Set the title document.title = title(active_profile)+" - " +connections[active_profile].chats[id].name; // Set the active chat active_chat = id; var next = function() { // Get the chat content element var chat_content = document.getElementById("chat-content"); // Scroll to the bottom of the div chat_content.scrollTop = chat_content.scrollHeight; // Focus the text area document.getElementById("chat-content-send-textarea").focus(); } // Register this to happen when shift enter is pressed in the textarea $("#chat-content-send-textarea").on('keydown', function(event) { // Is the keypress an enter if(event.keyCode == 13) { // Is shift pressed if(event.shiftKey) { // Submit the form chat_send(); } } }); // Try to scroll to the bottom of the div next(); setTimeout(next,1); } function chat_send() { // Get the message var message = document.getElementById("chat-content-send-textarea").value; // Get the date var date = new Date(); // Remove some data from the date date.setMilliseconds(0); date.setSeconds(0); // Is the message not empty and isnt a newline if(message.length > 0 && message != "\n") { // Send the message socket_write( connections[active_profile].client, connections[active_profile].encryption, { mode: "send_message", channel: active_chat, message: message, date: Date.parse(date) } ); } // Clear the textarea document.getElementById("chat-content-send-textarea").value = ""; // Focus the text area really soon setTimeout(function() { // Focus the text area document.getElementById("chat-content-send-textarea").focus(); }, 10); } function add_chat_menu() { // Set the html data document.getElementById("chat-area").innerHTML = "\

\ \ \
Name
\ \

\ "; } function add_chat() { // Send the data to the server socket_write( connections[active_profile].client, connections[active_profile].encryption, { mode: "new_chat", name: document.getElementById('add-chat-name').value } ); } function profiles_reload() { // Get the chat menu id var chat_menu = document.getElementById("server-menu-profiles"); // Reset it chat_menu.innerHTML = ""; // Loop over the profiles for(var i=0;i"+title(i)+""; // Add the profile to the menu chat_menu.appendChild(profile); } } } function edit_profile_mode_update() { // Get the mode var mode = document.getElementById("edit_profile_mode").value; // Is the mode direct if(mode == "direct") { // Clear the extra settings $(".edit_profile_proxy_section").addClass("off"); $(".edit_profile_proxy_section").removeClass("on"); } // Is the mode socks5 if(mode == "socks5") { // Set some extra settings $(".edit_profile_proxy_section").addClass("on"); $(".edit_profile_proxy_section").removeClass("off"); } } function switch_new_profile() { // Set the html document.title = "New Profile"; document.getElementById("chat-main").innerHTML = "\

New Profile:

\

\ \ \ \ \ \ \ \ \
Hostname
Port
Username
Password
Mode\ \
Proxy Host\
Proxy Port\
\ \

\ "; }