// 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"+users_array[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 = "";
// Loop over the messages
for(var i=0;i\
\
\
";
}
// 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;
}
function chat_send()
{
// Send the message
socket_write(
connections[active_profile].client,
connections[active_profile].encryption,
{
mode: "send_message",
channel: active_chat,
message: document.getElementById("chat-content-send-textarea").value
}
);
// 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 switch_new_profile()
{
// Set the html
document.title = "New Profile";
document.getElementById("chat-main").innerHTML = "\