mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
108 lines
3.1 KiB
JavaScript
Executable File
108 lines
3.1 KiB
JavaScript
Executable File
var Chat = {
|
||
|
||
namechange: function(newName)
|
||
{
|
||
socket.emit("namechange", newName);
|
||
Crypt.set_name(newName);
|
||
},
|
||
|
||
removename: function()
|
||
{
|
||
socket.emit("removename");
|
||
Crypt.remove_name();
|
||
},
|
||
|
||
chat: function(data)
|
||
{
|
||
if(data.value.length > 150)
|
||
return;
|
||
if(data.value.startsWith("/name ")){
|
||
Chat.namechange(data.value.substring(6));
|
||
}else if(data.value.startsWith("/removename")){
|
||
Chat.removename();
|
||
}
|
||
else if($(".chat-tab-li a.active").attr("href") == "#all_chat")
|
||
socket.emit("all,chat", data.value);
|
||
else
|
||
socket.emit("chat", data.value);
|
||
data.value = "";
|
||
return;
|
||
},
|
||
|
||
allchat_listener: function()
|
||
{
|
||
socket.on("chat.all", function(inp)
|
||
{
|
||
|
||
|
||
//$("#chat-btn").css("color", "grey");
|
||
|
||
console.log(inp.indexOf("changed name to"));
|
||
|
||
if(!blink_interval_exists && inp.indexOf("changed name to") < 0 && !chat_active)
|
||
{
|
||
$("#favicon").attr("href", "static/images/highlogo.png");
|
||
blink_interval_exists = true;
|
||
unseen = true;
|
||
blink_interval = setInterval(Chat.chat_blink, 2000);
|
||
}
|
||
|
||
if(document.hidden)
|
||
{
|
||
$("#favicon").attr("href", "static/images/highlogo.png");
|
||
}
|
||
var color = Helper.intToARGB(Helper.hashCode(inp[0]));
|
||
if(color.length < 6) {
|
||
for(x = color.length; x < 6; x++){
|
||
color = "0" + color;
|
||
}
|
||
}
|
||
color = Helper.hexToRgb(color.substring(0,6));
|
||
var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false);
|
||
$("#chatall").append("<li title='"+inp[2]+"''><span style='color:"+color_temp+";'>"+inp[0]+"</span></li>");
|
||
var in_text = document.createTextNode(inp[1]);
|
||
$("#chatall li:last")[0].appendChild(in_text);
|
||
document.getElementById("chatall").scrollTop = document.getElementById("chatall").scrollHeight;
|
||
});
|
||
},
|
||
|
||
setup_chat_listener: function(channel)
|
||
{
|
||
socket.on("chat", function(data)
|
||
{
|
||
if(!blink_interval_exists && data.indexOf("changed name to") < 0 && !chat_active)
|
||
{
|
||
$("#favicon").attr("href", "static/images/highlogo.png");
|
||
unseen = true;
|
||
blink_interval = setTimeout(Chat.chat_blink, 1000);
|
||
}
|
||
|
||
var color = Helper.intToARGB(Helper.hashCode(data[0]));
|
||
if(color.length < 6) {
|
||
for(x = color.length; x < 6; x++){
|
||
color = "0" + color;
|
||
}
|
||
}
|
||
color = Helper.hexToRgb(color.substring(0,6));
|
||
var color_temp = Helper.rgbToHsl([color.r, color.g, color.b], false);
|
||
$("#chatchannel").append("<li><span style='color:"+color_temp+";'>"+data[0]+"</span></li>");
|
||
var in_text = document.createTextNode(data[1]);
|
||
$("#chatchannel li:last")[0].appendChild(in_text);
|
||
document.getElementById("chatchannel").scrollTop = document.getElementById("chatchannel").scrollHeight;
|
||
});
|
||
},
|
||
|
||
chat_blink: function()
|
||
{
|
||
console.log("chat_blink");
|
||
$(".chat-link").css("color", "red");
|
||
setTimeout(function(){
|
||
$(".chat-link").css("color", "white");
|
||
|
||
if(unseen){
|
||
Chat.chat_blink();
|
||
}
|
||
}, 1000);
|
||
}
|
||
|
||
} |