document.addEventListener("visibilitychange", onchangevisibility);
function onchangevisibility (evt) {
if(!socket.connected) {
socket.disconnect();
socket.connect();
}
}
// Created by STRd6
// MIT License
// jquery.paste_image_reader.js
(function($) {
var defaults;
$.event.fix = (function(originalFix) {
return function(event) {
event = originalFix.apply(this, arguments);
if (event.type.indexOf('copy') === 0 || event.type.indexOf('paste') === 0) {
event.clipboardData = event.originalEvent.clipboardData;
}
return event;
};
})($.event.fix);
defaults = {
callback: $.noop,
matchType: /image.*/
};
return $.fn.pasteImageReader = function(options) {
if (typeof options === "function") {
options = {
callback: options
};
}
options = $.extend({}, defaults, options);
return this.each(function() {
var $this, element;
element = this;
$this = $(this);
return $this.bind('paste', function(event) {
var clipboardData, found;
found = false;
clipboardData = event.clipboardData;
return Array.prototype.forEach.call(clipboardData.types, function(type, i) {
var file, reader;
if (found) {
return;
}
if (type.match(options.matchType) || clipboardData.items[i].type.match(options.matchType)) {
file = clipboardData.items[i].getAsFile();
reader = new FileReader();
reader.onload = function(evt) {
return options.callback.call(element, {
dataURL: evt.target.result,
event: evt,
file: file,
name: file.name
});
};
reader.readAsDataURL(file);
return found = true;
}
});
});
});
};
})(jQuery);
var points = {};
var is_vip;
var tps = ["pt","tp","nm","m","p","mn","tp?","pt?","nm?","moi tp"];
var tpsblack = "spons";
var blacklistwords = "7612556";
var msgcounter = 0;
var othermsgcounter = 0;
function markuptext(text,identifier,htmltag)
{
var array = text.split(identifier);
var previous = "";
var previous_i;
for (i = 0; i < array.length; i++) {
if (i % 2)
{
array[i] = identifier + array[i];
}
else if (i!=0)
{
previous_i = eval(i-1);
array[previous_i] = "<"+htmltag+">"+(previous.replace(identifier,''))+""+htmltag+">";
}
previous = array[i];
}
var newtext = "";
for (i = 0; i < array.length; i++) {
newtext += array[i];
}
return newtext;
}
if(localStorage.guestsession == undefined || localStorage.guestsession == "") {
localStorage.guestsession = getCookie("guestsession");
}else {
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = "guestsession=" + localStorage.guestsession + ";expires=" + myDate
+ ";domain=.panettaa.org;path=/";
}
function isIEorEDGE(){
if (navigator.appName == 'Microsoft Internet Explorer'){
return true; // IE
}
else if(navigator.appName == "Netscape"){
return navigator.appVersion.indexOf('Edge') > -1; // EDGE
}
return false;
}
(function (window) {
var on, off;
function Webkit() {
if (window.webkitRequestFileSystem) {
window.webkitRequestFileSystem(window.TEMPORARY, 1, off, on);
return true;
}
}
function Mozilla() {
if ('MozAppearance' in document.documentElement.style) {
const db = indexedDB.open('test');
db.onerror = on;
db.onsuccess = off;
return true;
}
}
function Safari() {
if (/constructor/i.test(window.HTMLElement)) {
// iOS 11
// Origin: https://gist.github.com/cou929/7973956#gistcomment-2272103
try {
window.openDatabase(null, null, null, null);
} catch (e) {
on();
}
// Older Safari
try {
if (localStorage.length)
off();
else {
localStorage.x = 1;
localStorage.removeItem('x');
off();
}
} catch (e) {
// Original gist: https://gist.github.com/jherax/a81c8c132d09cc354a0e2cb911841ff1
// Safari only enables cookie in private mode
// if cookie is disabled then all client side storage is disabled
// if all client side storage is disabled, then there is no point
// in using private mode
navigator.cookieEnabled ? on() : off();
}
return true;
}
}
function IE10Edge() {
if (!window.indexedDB && (window.PointerEvent || window.MSPointerEvent)) {
on();
return true;
}
}
window.isPrivate = function (on_cb, off_cb) {
on = on_cb || function () {};
off = off_cb || function () {};
Webkit() || Mozilla() || Safari() || IE10Edge() || off();
};
})(window);
var giphy = new Giphy('202e65055083428f9c591660c12eee9b');
function giphyclick(that,timeout) {
if(timeout != 1 || $(that).attr("data-running") == "1") {
$(that).find(".giphyimg").toggle();
$(that).find("video").toggle();
$(that).find(".gifplay").toggle();
if($(that).attr("data-running") == "1") {
$(that).attr("data-running","0");
$(that).find("video")[0].pause();
} else {
$(that).attr("data-running","1");
$(that).find("video")[0].play();
}
setTimeout(function() { giphyclick(that,1); },30000);
}
}
function iOS() {
var iDevices = [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
];
if (!!navigator.platform) {
while (iDevices.length) {
if (navigator.platform === iDevices.pop()){ return true; }
}
}
return false;
}
if(iOS()) {
document.addEventListener('touchmove', function (event) {
if (event.scale !== 1) { event.preventDefault(); }
}, false);
var lastTouchEnd = 0;
document.addEventListener('touchend', function (event) {
var now = (new Date()).getTime();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
$(".messageinput").css("font-size","16px");
}
var currentcam = 0;
var videoDevices = [];
function changecamera() {
webrtc.stopLocalVideo();
webrtc.leaveRoom();
$("#localVideo").html("");
webrtc.webrtc.localStreams = new Array();
videoDevices = [];
navigator.mediaDevices.enumerateDevices().then(function (devices) {
for (var i = 0; i !== devices.length; ++i) {
var device = devices[i];
if (device.kind === 'videoinput') {
device.label = device.label || 'camera ' + (videoDevices.length + 1);
videoDevices.push(device);
}
}
//default media options
var mediaOptions = {
audio: true,
video: true
};
if(videoDevices.length <= (currentcam+1))
currentcam = -1;
currentcam++;
webrtc.config.media.video.deviceId = videoDevices[currentcam].deviceId;
webrtc.startLocalVideo();
setTimeout(function() {
webrtc.joinRoom(roomid[0]);
},1000);
});
}
is_vip = true; var iud = 0;
$( document ).ready(function() {
setTimeout(winresize,100);
setsets();
winresize();
if(iud != 0) {
$( '.chat[data-id="' + iud + '"] .messageinput').focus(function() {
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + iud});
socket.emit('meta', { room: roomid[iud], user: userid[iud], data: { readed: true } });
});
}
$('.chat[data-id="' + iud + '"] textarea').autosize({append: ""});
messageheight = $('.chat[data-id="' + iud + '"] textarea').height();
//PROBLEM
$('.chat[data-id="' + iud + '"] .medias').popover({ html : true,content: function() {
return $('#media').html();
}});
$('.chat[data-id="' + iud + '"] .medias').on('shown.bs.popover', function () {
openid = iud;
$('.chat:not([data-id="' + iud + '"]) .medias').popover('hide');
});
$('.chat[data-id="' + iud + '"] .picupload').popover({placement: 'top', html : true,content: function() {
return $('#picup').html();
}});
$('.chat[data-id="' + iud + '"] .audioupload').popover({placement: 'top', html : true,content: function() {
return $('#audioup').html();
}});
$('.chat[data-id="' + iud + '"] .gifupload').popover({placement: 'top', html : true,content: function() {
return $('#gifup').html();
}});
$('.chat[data-id="' + iud + '"] .videoupload').popover({placement: 'top', html : true,content: function() {
return $('#videoup').html();
}});
$('.chat[data-id="' + iud + '"] .smileybtn').popover({ template: '
', html : true,content: function() {
return $('#smileys').html();
}});
$('.chat[data-id="' + iud + '"] .drawbtn').popover({ placement: 'top',template: '', html : true,content: function() {
return $('#draws').html();
}});
$('.chat[data-id="' + iud + '"] .drawbtn').on('shown.bs.popover', function () {
if(drawns != 1) {
var data = "";
data = '';
$.each([ "#f00", "#ff0", "#0f0", "#0ff", "#00f", "#f0f", "#fff", "#C0C0C0" , "#808080", "#000", "#800000", "#800080" , "#FF7F00", "#008000", "#808000" , "#000080", "#964B00","#C0DCC0","#A6CAF0","#FFFBF0"], function() {
data = data + "
x ";
});
data = data + '
';
data = data + "
";
$.each([1, 3, 5, 10], function() {
data = data + "
" + this + " ";
});
data = data + "
";
data = data + "
";
$(".drawtools").append(data + '
');
drawns = 1;
}
$("#colors_sketch").sketch();
$(".drawsizerbtn").click(function() {
$(".triggersizechange").val($(this).attr("data-size"));
});
$(".triggersizechange").on('keyup mouseup',function() {
$(".drawsizebtn").attr("data-size",$(this).val());
$(".drawsizebtn").click();
});
});
$('#settings').popover({ html : true,content: function() {
return $('#setting').html();
}});
$('#settings2').popover({ html : true,content: function() {
return $('#setting').html();
}});
$('#addfriends').popover({ html : true,content: function() {
return $('#addfriend').html();
}});
$('.disconnect').click(function(){
if(disconnected == 0) {
if($(this).hasClass("sure")) {
disconnect(0);
disconnected = 1;
} else {
$(this).html(' Varmasti?').addClass("sure");
myVar = setTimeout(function(){
$('.disconnect').html(' Katkaise (ESC) ').removeClass("sure");},2000);
}
} else {
searchpartner();
disconnected = 0;
}
});
});
var webrtc;
function addemo(data,proid) {
if(proid != 1)
$(".messageinput[data-id='" + iud + "']").val($(".messageinput").val()+" "+data+" ");
else
$(".messageinput[data-id='" + iud + "']").val($(".messageinput").val()+""+data+" ").focus();
}
function getroommessages() {
if(gid != undefined) {
$.post("//panettaa.org/handler.php", {
getroommessages : "true",
rid: location.pathname.substring(location.pathname.lastIndexOf("/") + 1).slice(0,-5)
}).done(function (data) {
//$(".chat-window[data-id='0'] .chatdata").html("");
if(data != "") {
var arr = JSON.parse(data);
$.each(arr, function(idx, obj) {
if(obj.user == userid[iud])
who = 1;
else
who = 2;
obj.message = htmlencode(obj.message);
if(obj.meta != undefined) {
if(obj.meta.type == 6 || obj.meta.type == 3 || obj.meta.type == 4 || obj.meta.type == 5)
obj.meta.type = 0;
if(obj.meta.time != undefined)
newmsg(obj.message,roomid[iud],who,obj.created,gid[obj.user],obj.meta.type,undefined,1);
else
newmsg(obj.message,roomid[iud],who,obj.created,gid[obj.user],obj.meta.type,undefined,1);
} else
newmsg(obj.message,roomid[iud],who,obj.created,gid[obj.user],undefined,undefined,1);
});
}
if(answercall == 1)
answerwebcam(0,iud);
else if(answercall == 2)
answerwebcam(1,iud);
downscroll(iud);
});
} else {
setTimeout(function() { getroommessages(); },500);
}
}
function report() {
bootbox.prompt("Syy ilmoitukselle?", function(result) {
if (result === null) {
} else {
$.post( '//panettaa.org/handler.php', { syy: result, room: roomid[0], user: userid[0], typety: type },
function( data ) {
if (data == 'true') {
bootbox.alert("Kiitos ilmoituksesta! Ylläpito katsoo sen pian.");
}
}
);
}
});
}
var breporttime;
function breport() {
if($(".blackvideo").hasClass("sure")) {
$.post( '//panettaa.org/handler.php', { blackreason: 1, room: roomid[0], user: userid[0], typety: type },
function( data ) {
$(".blackvideo").removeClass("sure").attr("disabled",true);
$(".blackvideo span").html(" Kiitos!");
breporttime = setTimeout(function() {
$(".blackvideo").removeClass("sure").attr("disabled",true);
$(".blackvideo span").html(" Ilmoita kuvaton!");
},3000);
}
);
} else {
$(".blackvideo").addClass("sure");
$(".blackvideo span").html("Varma?");
breporttime = setTimeout(function() {
$(".blackvideo").removeClass("sure");
$(".blackvideo span").html(" Ilmoita kuvaton!");
},2000);
}
}
function callwebcam() {
$(".medias").popover("hide");
if(openid == localStorage.bigroom || chaton != 1) {
newmsg("Soitetaan Randomille",roomid[openid],0,0,0);
socket.emit('message', { room: roomid[openid], user: userid[openid], message: "Seurasi haluaa aloittaa videopuhelun", meta: { type: 3, time: 1 } });
} else {
newmsg("Et voi aloittaa videopuhelua ikkunassa, jossa sinulla on chat käynnissä.",roomid[openid],0,0,0);
}
}
function answerwebcam(whois,pal) {
if(pal == undefined)
var pal = 0;
if(vready == 1) {
continuewebcam(whois);
} else {
//loadScript("//panettaa.org/js/adapter.min.js", function(){});
loadScript("//panettaa.org/js/webrtc_v3.js?v=643643", function(){
continuewebcam(whois);
});
}
}
function continuewebcam(whois) {
$(".chatblock").removeClass("col-sm-12 col-md-12").addClass("col-sm-6 col-md-8");
$(".chatform").removeClass("col-md-12").addClass("col-sm-6 col-sm-offset-6 col-md-8 col-md-offset-4");
$(".camblock").show();
$(".callingans").parent().parent().remove();
if(webrtc == undefined) {
var signalurl = 'https://chats3.randomi.fi:8889';
webrtc = new SimpleWebRTC({
url: aignalurl,
localVideoEl: 'localVideo',
remoteVideosEl: 'remoteVideo',
media: {
video: {
width: { min: 0, ideal: 640, max: 640 },
height: { min: 0, ideal: 480, max: 480 }
},
audio: true
}
});
vready = 1;
continuewebcam(whois);
} else {
$("#remoteVideo").html("");
$("#localVideo").html("");
webrtc.startLocalVideo();
webrtc.on('localStreamRequestFailed', function () {
$(".searching").html("Emme saa oikeuksia kameraan ja mikrofoniisi. Tarkista asetuksesi.");
$("#remoteVideo").html(" Emme saa oikeuksia kameraan ja mikrofoniisi. Tarkista asetuksesi.");
});
webrtc.on('readyToCall', function () {
webrtc.joinRoom(roomid[openid]);
socket.emit('meta', { room: roomid[openid], user: userid[openid], data: { readed: true } });
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + openid});
});
if(whois != 1) {
newmsg("Sinä vastasit puheluun",roomid[openid],0,0,0);
socket.emit('message', { room: roomid[openid], user: userid[openid], message: "Seurasi vastasi", meta: { type: 4, time: 1 }});
}
}
}
function closewebcam(whois) {
webrtc.leaveRoom();
$(".chatblock").removeClass("col-sm-6 col-md-8").removeClass("col-sm-4 col-md-4").addClass("col-sm-12 col-md-12");
$(".chatform").removeClass("col-sm-6 col-sm-offset-6 col-md-8 col-md-offset-4").removeClass("col-sm-6 col-sm-offset-6 col-md-4 col-md-offset-8").addClass("col-md-12");
$(".camblock").hide().addClass("col-sm-6 col-md-4").removeClass("bigger col-sm-8 col-md-8");
webrtc.stopLocalVideo();
socket.emit('meta', { room: roomid[openid], user: userid[openid], data: { readed: true } });
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + openid});
$("#remoteVideo").html("");
$("#localVideo").html("");
if(whois != 1) {
newmsg("Sinä lopetit puhelun",roomid[openid],0,0,0);
socket.emit('message', { room: roomid[openid], user: userid[openid], message: "Seurasi lopetti puhelun", meta: { type: 5, time: 1 }});
}
}
function denywebcam(whois,pal) {
$(".callingans").parent().parent().remove();
newmsg("Sinä hylkäsit puhelun",roomid[pal],0,0,0);
socket.emit('message', { room: roomid[pal], user: userid[pal], message: "Seurasi hylkäsi puhelun", meta: { time: 1 }});
socket.emit('meta', { room: roomid[openid], user: userid[openid], data: { readed: true } });
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + openid});
}
function webcam() {
$(".chatblock").toggleClass("col-sm-12 col-md-12").toggleClass("col-sm-6 col-md-8");
$(".camblock").toggle();
}
function pausewebcam(forced) {
if($(".pausewebcam").hasClass("paused") || forced == 1) {
webrtc.resumeVideo();
if(!$(".mutewebcam").hasClass("paused"))
webrtc.unmute();
$(".pausewebcam").removeClass("paused").html(' Pysäytä');
} else {
webrtc.pauseVideo();
webrtc.mute();
$(".pausewebcam").addClass("paused").html(' Jatka');
}
}
function mutewebcam() {
if($(".mutewebcam").hasClass("paused")) {
webrtc.unmute();
$(".mutewebcam").removeClass("paused").html(' Mykistä');
} else {
webrtc.mute();
$(".mutewebcam").addClass("paused").html(' Poista myk.');
}
}
function biggerwebcam() {
if($(".camblock").hasClass("bigger")) {
$(".chatblock").addClass("col-sm-6 col-md-8").removeClass("col-sm-4 col-md-4");
$(".camblock").addClass("col-sm-6 col-md-4").removeClass("bigger col-sm-8 col-md-8");
$(".chatform").addClass("col-md-8 col-md-offset-4").removeClass("col-sm-6 col-sm-offset-6 col-md-4 col-md-offset-8");
$(".webcam#localVideo").css("opacity","1");
if(mobilesize == 0)
setTimeout(function() { $(".webcam#remoteVideo, .webcam#localVideo").height($(".chatblock").height()/2); },200);
else {
$(".webcam#remoteVideo").height(($( window ).height()-61-79-10)/3*2);
$(".webcam#localVideo").height(($( window ).height()-61-79-10)/3);
}
} else {
$(".chatblock").removeClass("col-sm-6 col-md-8").addClass("col-sm-4 col-md-4");
$(".camblock").removeClass("col-sm-6 col-md-4").addClass("bigger col-sm-8 col-md-8");
$(".chatform").removeClass("col-md-8 col-md-offset-4").addClass("col-sm-6 col-sm-offset-6 col-md-4 col-md-offset-8");
$(".webcam#localVideo").css("opacity","0.8").height("150");
$(".webcam#remoteVideo").height($(".chatblock").height());
if(mobilesize == 1) {
$(".webcam#remoteVideo").height(($( window ).height()-61-79-10));
$(".webcam#localVideo").height(($( window ).height()-61-79-10)/4);
}
}
}
Webcam.set({
width: 320,
height: 240,
dest_width: 640,
dest_height: 480,
image_format: "jpeg",
jpeg_quality: 90,
force_flash: false
});
function empty() {
$('.chat-window[data-id="0"] ul').html('');
}
function game() {
$(".chatblock").toggleClass("col-sm-12 col-md-12").toggleClass("col-sm-4 col-md-6");
$(".gameblock").toggle();
$(".medias").popover("hide");
}
function webcampic() {
$("#picupform").html('
');
$("#picupform").parent().parent().css("top","-274px");
Webcam.attach("#my_camera");
}
function takewebcam() {
Webcam.freeze();
$(".cambtns").html('Peruuta Lähetä! ');
}
function cancelwebcam() {
Webcam.unfreeze();
$(".cambtns").html('Sulje Ota ');
}
var lastimageload = 0;
$(".messageinput[data-id=0]").pasteImageReader(function(datax) {
if(datax.event.loaded != lastimageload && confirm("Lähetä kuva?")) {
lastimageload = datax.event.loaded;
var image_fmt = datax.file.type.replace("image/","");
var data_uri = datax.dataURL;
var url = "//panettaa.org/inc/upload.php?type=11&format=" + image_fmt;
Webcam.upload( data_uri, url, function(code, text) {
if(type == "group" || type == "chatroom")
newmsg(text, roomid[openid], 1,0,gid[userid[openid]],1);
else
newmsg(text, roomid[openid], 1,0,0,1);
lastmsg = text;
socket.emit('message', { room: roomid[openid], user: userid[openid], message: text, meta: { type: 1 } });
} );
}
});
function sendwebcam() {
Webcam.snap( function(data_uri) {
var image_fmt = "jpeg";
var url = "//randomi.fi/inc/upload.php?type=2&format=" + image_fmt;
Webcam.freeze();
Webcam.upload( data_uri, url, function(code, text) {
Webcam.reset();
if(type == "group" || type == "chatroom")
newmsg(text, roomid[openid], 1,0,gid[userid[openid]],1);
else
newmsg(text, roomid[openid], 1,0,0,1);
lastmsg = text;
socket.emit('message', { room: roomid[openid], user: userid[openid], message: text, meta: { type: 1 } });
$("#picupload").popover("hide");
$(".picupload").popover("hide");
} );
} );
}
function closeweb() {
Webcam.reset();
$("#picupload").popover("hide");
$(".picupload").popover("hide");
}
var last_uri;
function uploaddraw(data_uri) {
if(data_uri != last_uri) {
last_uri = data_uri;
data_uri = data_uri.slice(data_uri.indexOf() + 1);
var image_fmt = "png";
var url = "//randomi.fi/inc/upload.php?type=1&format=" + image_fmt;
Webcam.upload( data_uri, url, function(code, text) {
if(type == "group" || type == "chatroom")
newmsg(text, roomid[openid], 1,0,gid[userid[openid]],2);
else
newmsg(text, roomid[openid], 1,0,0,2);
lastmsg = text;
socket.emit('message', { room: roomid[openid], user: userid[openid], message: text, meta: { type: 2 } });
$("#drawbtn").popover("hide");
$(".drawbtn").popover("hide");
} );
}
}
function rejectuser() {
$.post("//panettaa.org/handler.php", {
rejectuser : userid[0],
typety : type
})
.done(function (data) {
if(data != "") {
$(".ignoreuserss").html("Kumppani estetty");
}
});
}
function givekarma() {
$.post("//panettaa.org/handler.php", {
givekarma : userid[0],
typety : type
})
.done(function (data) {
if(data != "") {
$(".goodpartner").html("Kiitos");
}
});
}
function showchat() {
if($(".chatblock").hasClass("open")) {
$(".chatblock").addClass("hidden-xs").removeClass("open");
$(".chatinputs").addClass("mobilevideoinputsvisi");
$(".showchat").removeClass("btn-primary").addClass("btn-success");
} else {
$(".chatblock").removeClass("hidden-xs").addClass("open");
$(".chatinputs").removeClass("mobilevideoinputsvisi");
clearInterval(videointi);
$(".showchat").removeClass("btn-primary").addClass("btn-success");
}
}
function ignoreuser($this,user,force) {
if($this.hasClass("varma") || force == 1) {
clearTimeout(myVar);
if(force == 1)
$this.replaceWith(' ');
else
$this.html("Kumppani estetty");
$(".chatdata li[data-user=" + user + "]").hide();
ignoredusers.push(user);
} else {
$this.addClass("varma");
$this.html("Varmasti?");
myVar = setTimeout(function(){
$this.html(' ').removeClass("varma");},2000);
}
}
function removeignore($this,user,force) {
var index = ignoredusers.indexOf(user);
if (index > -1) {
ignoredusers.splice(index, 1);
}
if(force == 1)
$this.replaceWith(' ');
else
$this.remove();
$(".chatdata li[data-user=" + user + "]").show();
}
function addfriend() {
$('#addfriends').popover('hide');
$.post("//panettaa.org/handler.php", {
addfriend : userid[0],
rid: roomid[0]
})
.done(function (data) {
if(data == "true") {
newmsg("Sinä pyysit käyttäjää kaveriksi.",roomid[0],0,0,0);
socket.emit("message", { room: roomid[0], user: userid[0], message: "Seurasi pyytää sinua kaverikseen.", meta: { type: 6, time: 1 }});
$("#addfriends").attr("disabled","disabled");
} else {
bootbox.dialog({
message: '',
title: "Kirjaudu tai Rekisteröidy!",
buttons: {
danger: {
label: "Peruuta",
className: "btn-danger",
callback: function() {
}
}
}
});
}
});
}
function rejectfriend() {
newmsg("Sinä hylkäsit kaveripyynnön",roomid[0],0,0,0);
socket.emit("message", { room: roomid[0], user: userid[0], message: "Seurasi hylkäsi kaveripyynnön", meta: { type: 7, time: 1 }});
$(".askfriend").parent().remove();
}
function acceptfriend() {
$.post("//panettaa.org/handler.php", {
acceptfriend : userid[0],
rid: roomid[0],
typ: type
})
.done(function (data) {
if(data == "true") {
newmsg("Olette nyt kavereita",roomid[0],0,0,0);
socket.emit("message", { room: roomid[0], user: userid[0], message: "Olette nyt kavereita", meta: { type: 8, time: 1 }});
keepactive = 1;
$(".askfriend").parent().remove();
} else {
bootbox.dialog({
message: '',
title: "Kirjaudu tai Rekisteröidy!",
buttons: {
danger: {
label: "Peruuta",
className: "btn-danger",
callback: function() {
}
}
}
});
}
});
}
function submitpic() {
var bar = $(".progress-bar");
var percent = $(".percent");
var statusi = $(".uploadstatus");
if($("#picupform input").val() != "") {
$("#picupform").ajaxSubmit({
beforeSend: function() {
var percentVal = "0%";
bar.width(percentVal)
percent.html(percentVal);
$(".progress").height(70);
$(".popover").css("opacity","0.8");
$(".popover").css("height","70px");
},
uploadProgress: function(event, position, total, percentComplete) {
$("#picupform").css("visibility","hidden");
$(".proress").show();
var percentVal = percentComplete + "%";
bar.width(percentVal);
percent.html(percentVal);
},
success: function() {
var percentVal = "100%";
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
if(xhr.responseText.length > 5000) {
statusi.html("Unohdit kuvan.");
} else {
$(".proress").hide();
if(type == "group" || type == "chatroom")
newmsg(xhr.responseText, roomid[openid], 1,0,gid[userid[openid]],1);
else
newmsg(xhr.responseText, roomid[openid], 1,0,0,1);
lastmsg = xhr.responseText;
socket.emit('message', { room: roomid[openid], user: userid[openid], message: xhr.responseText, meta: { type: 1 } });
$(".popover").css("opacity","1");
$("#picupform").css("visibility","inherit");
$(".popover").css("height","inherit");
$("#picupload").popover("hide");
$(".picupload").popover("hide");
}
$(".submit").removeAttr("disabled");
}
});}}/* CHAT */
var presumable = new Resumable({
target:'//randomi.fi//inc/upload.php',
query:{upload_token:Math.random().toString(36).replace(/[^a-z0-9]+/g, '')},
maxFiles : 1,
fileType: ["image/*"],
});
var bar = $(".progress-bar");
var percent = $(".percent");
var statusi = $(".uploadstatus");
var isSuccess = false;
presumable.on('fileAdded', function(file, event){
$(".popover").css("opacity","0.8");
bar = $(".progress-bar");
percent = $(".percent");
statusi = $(".uploadstatus");
presumable.upload();
var percentVal = "0%";
bar.width(percentVal)
percent.html(percentVal);
$(".progress2").height(70);
$(".popover").css("opacity","0.8");
$(".popover").css("height","70px");
$("#picoupform").css("visibility","hidden");
$(".proress").show();
});
presumable.on('fileRetry', function(file){
console.debug('fileRetry', file);
});
presumable.on('fileError', function(file, message){
console.debug('fileError', file, message);
});
presumable.on('uploadStart', function(){
console.debug('uploadStart');
});
presumable.on('fileSuccess', function(file, message){
var percentVal = "100%";
bar.width(percentVal)
percent.html(percentVal);
isSuccess = true;
if(message.length > 5000) {
statusi.html("Unohdit kuvan.");
} else {
$(".proress").hide();
if(message != "error" && isSuccess !== false) {
if(type == "group" || type == "chatroom")
newmsg(message, roomid[openid], 1,0,gid[userid[openid]],1);
else
newmsg(message, roomid[openid], 1,0,0,1);
lastmsg = message;
socket.emit('message', { room: roomid[openid], user: userid[openid], message: message, meta: { type: 1 } });
}
$("#picupform").css("visibility","inherit");
$(".popover").css("opacity","1");
$(".popover").css("height","inherit");
$("#picupload").popover("hide");
$(".picupload").popover("hide");
}
$(".submit").removeAttr("disabled");
});
presumable.on('fileProgress', function(file, message){
$("#picupform").css("visibility","hidden");
$(".proress").show();
var percentVal = parseInt(file.progress()*100) + "%";
bar.width(percentVal);
percent.html(percentVal);
});
presumable.on('error', function(message, file){
console.debug('error', message, file);
});
presumable.on('pause', function(){
console.debug('pause');
});
presumable.on('cancel', function(){
console.debug('cancel');
});
var vresumable = new Resumable({
target:'//randomi.fi//inc/vupload_new.php',
query:{upload_token:Math.random().toString(36).replace(/[^a-z0-9]+/g, '')},
maxFiles : 1,
fileType: ["video/*"],
});
var bar = $(".progress-bar.videobar");
var percent = $(".percent.videobar");
var statusi = $(".uploadstatus.videobar");
var isSuccess = false;
vresumable.on('fileAdded', function(file, event){
bar = $(".progress-bar.videobar");
percent = $(".percent.videobar");
statusi = $(".uploadstatus.videobar");
isSuccess = false;
vresumable.upload();
var percentVal = "0%";
bar.width(percentVal)
percent.html(percentVal);
$(".progress2.videobar").height(70);
$(".popover").css("opacity","0.8");
$(".popover").css("height","70px");
$("#videoupform").css("visibility","hidden");
$(".proress.videobar").show();
});
vresumable.on('fileRetry', function(file){
console.debug('fileRetry', file);
});
vresumable.on('fileError', function(file, message){
console.debug('fileError', file, message);
});
vresumable.on('uploadStart', function(){
console.debug('uploadStart');
});
vresumable.on('fileSuccess', function(file, message){
var percentVal = "100%";
bar.width(percentVal)
percent.html(percentVal);
isSuccess = true;
if(message.length > 5000) {
statusi.html("Unohdit videon.");
} else {
$(".proress.videobar").hide();
if(message != "error" && isSuccess !== false) {
if(type == "group" || type == "chatroom")
newmsg(message, roomid[openid], 1,0,gid[userid[openid]],11);
else
newmsg(message, roomid[openid], 1,0,0,11);
lastmsg = message;
socket.emit("message", { room: roomid[openid], user: userid[openid], message: message, meta: { type: 11 } });
}
$("#videoupform").css("visibility","inherit");
$(".popover").css("opacity","1");
$(".popover").css("height","inherit");
$("#videoupload").popover("hide");
$(".videoupload").popover("hide");
}
$(".submit").removeAttr("disabled");
});
vresumable.on('fileProgress', function(file, message){
$(".proress.videobar").show();
var percentVal = parseInt(file.progress()*100) + "%";
bar.width(percentVal);
percent.html(percentVal);
});
vresumable.on('error', function(message, file){
console.debug('error', message, file);
});
vresumable.on('pause', function(){
console.debug('pause');
});
vresumable.on('cancel', function(){
console.debug('cancel');
});
function submitvideo() {
var bar = $(".progress-bar.videobar");
var percent = $(".percent.videobar");
var statusi = $(".uploadstatus.videobar");
var isSuccess = false;
if($("#videoupform input").val() != "") {
$("#videoupform").ajaxSubmit({
beforeSend: function() {
var percentVal = "0%";
bar.width(percentVal)
percent.html(percentVal);
$(".progress2.videobar").height(70);
$(".popover").css("opacity","0.8");
$(".popover").css("height","70px");
},
uploadProgress: function(event, position, total, percentComplete) {
$("#videoupform").css("visibility","hidden");
$(".proress.videobar").show();
var percentVal = percentComplete + "%";
bar.width(percentVal);
percent.html(percentVal);
},
success: function(response, textStatus, xhr, form) {
var percentVal = "100%";
bar.width(percentVal)
percent.html(percentVal);
isSuccess = true;
},
error: function(xhr, textStatus, errorThrown) {
console.log("in ajaxForm error");
},
complete: function(xhr) {
if(xhr.responseText.length > 5000) {
statusi.html("Unohdit videon.");
} else {
$(".proress.videobar").hide();
if(xhr.responseText != "error" && isSuccess !== false) {
if(type == "group" || type == "chatroom")
newmsg(xhr.responseText, roomid[openid], 1,0,gid[userid[openid]],11);
else
newmsg(xhr.responseText, roomid[openid], 1,0,0,11);
lastmsg = xhr.responseText;
socket.emit("message", { room: roomid[openid], user: userid[openid], message: xhr.responseText, meta: { type: 11 } });
}
$("#videoupform").css("visibility","inherit");
$(".popover").css("opacity","1");
$(".popover").css("height","inherit");
$("#videoupload").popover("hide");
$(".videoupload").popover("hide");
}
$(".submit").removeAttr("disabled");
}
});}}
var gid;
var gids = [];
var gidusers = [];
var inputs = [0];
var spams = [0];
var type = "";
var chatintype = "";
var time = "";
var whoe = "";
var lastmsg = "";
var latestmsg = "";
var whois = ["","Minä","Seurasi"];
var whoisdesktop = ["","Minä","Seurasi"];
var whoismobile = ["","M","S"];
var ismobile = 0;
var ignoredusers = [];
var chaton = 0;
var chatis = 0;
var vready = 0;
var swebrtc = 0;
var updating;
var msgcount = 0;
var tabwidth = 0;
var disconnected = 0;
var myVar;
var status;
var said = 0;
var write = 0;
var dcount = 0;
var lcon = 0;
var error = 0;
var nottop = 0;
var mobilesize = 0;
function validateCode(TCode){
if( /[^a-zA-Z0-9]/.test( TCode ) ) {
return false;
}
return true;
}
var chattypes = ["normal","match","video","group"];
var hashdata = location.hash.split("/");
/* Check hash-data */
if(location.hash != "" && location.hash != "#disconnected") {
if(hashdata[2].length == 32 && validateCode(hashdata[2])) {
if(chattypes.indexOf(hashdata[0].substring(1)) !== -1)
type = hashdata[0].substring(1);
chatintype = hashdata[0].substring(1);
userid[0] = hashdata[2];
roomid[0] = hashdata[1];
if(type == "video") {
$(".chatblock").addClass("hidden-xs mobilevideo");
$(".chatinputs").addClass("mobilevideoinputs mobilevideoinputsvisi");
$("#remoteVideo").html('Etsitään seuraa... ');
}
}
}
var vready2 = 0;
if(type == "video" || "friend" == "video") {
$(".chatblock").toggleClass("col-sm-12 col-md-12").toggleClass("col-sm-6 col-md-8");
$(".chatform").toggleClass("col-md-12").toggleClass("col-sm-6 col-sm-offset-6 col-md-8 col-md-offset-4");
$(".camblock").toggle();
$(".pausewebcam, .pausewebcam2").toggle();
$(".closewebcam").remove();
$(".gonline").addClass("hidden-xs").html('').show();
var signalurl = 'https://chats3.randomi.fi:8889';
webrtc = new SimpleWebRTC({
url: signalurl,
localVideoEl: 'localVideo',
remoteVideosEl: 'remoteVideo',
autoRequestMedia: true,
media: {
video: {
width: { min: 0, ideal: 640, max: 640 },
height: { min: 0, ideal: 480, max: 480 }
},
audio: true
}
});
if(DetectRTC.RTCPeerConnection === false) {
$(".searching").html("Selaimesi ei tue videochatin ominaisuuksia. Kokeile videochattia esim. Google Chromella.");
$("#remoteVideo").html(" Selaimesi ei tue videochatin ominaisuuksia. Kokeile videochattia esim. Google Chromella.");
}
webrtc.on('localStreamRequestFailed', function () {
$(".searching").html("Emme saa oikeuksia kameraan ja mikrofoniisi. Tarkista asetuksesi.");
$("#remoteVideo").html(" Emme saa oikeuksia kameraan ja mikrofoniisi. Tarkista asetuksesi.");
});
webrtc.on('readyToCall', function () {
vready = 1;
chatis = 1;
if(vready2 == 0)
search("friend");
vready2 = 1;
});
function blackdetect() {
try {
if(trackerTask == undefined) {
var FastTracker = function() {
FastTracker.base(this, 'constructor');
};
tracking.inherits(FastTracker, tracking.Tracker);
tracking.Fast.THRESHOLD = 3;
FastTracker.prototype.threshold = tracking.Fast.THRESHOLD;
FastTracker.prototype.track = function(pixels, width, height) {
setTimeout(function() {trackerTask.stop();},0);
var gray = tracking.Image.grayscale(pixels, width, height);
var corners = tracking.Fast.findCorners(gray, width, height);
this.emit('track', {
data: corners.length
});
};
var tracker = new FastTracker();
tracker.on('track', function(event) {
var corners = event.data;
dovideolol(corners);
});
var trackerTask = tracking.track('#localVideo video', tracker);
} else {
trackerTask.run();
}
} catch (e) {
dovideolol(9999999);
}
}
function dovideolol(corners) {
if(corners < 50) {
if($(".chatdata .searching").length > 0) {
newmsg("Haku pysäytettiin mustan ruudun vuoksi");
disconnect(0);
disconnected = 1;
$("#remoteVideo").html('Haku pysäytettiin mustan ruudun vuoksi ');
}
}
}
} else {
}
var moretabs = 0;
function tabs(ty) {
if(ty == 1) {
if(moretabs == 0) {
$("#minichats").prepend('>
');
$("#minichats").append('<
');
moretabs = 1;
}
var totalWidth = 0;
$("#minichats .chat").each(function(index) {
totalWidth += parseInt($(this).width(), 10) + 14;
if((totalWidth + 200) > $( window ).width()) {
$(this).hide();
} else {
$(this).show();
}
});
} else {
$(".moretab").remove();
$("#minichats .chat").show();
moretabs = 0;
}
}
function tabmiz() {
var totalWidth = 0;
$("#minichats .chat").each(function(index) {
totalWidth += parseInt($(this).width(), 10) + 14;
});
if($( window ).width() < (totalWidth + 200))
tabs(1);
else
tabs(0);
}
function winresize() {
if(type == "chatroom" && $(".chatblock iframe").length > 0) {
$(".chatblock .chat-window").height("300");
} else {
if($( window ).width() < 769) {
if(type == "video")
$(".chatblock .chat-window").height(($( window ).height()-60-50-22));
else
$(".chatblock .chat-window").height(($( window ).height()-60-60-10));
$("body").attr("style","padding-bottom: 0px !important;");
$(".webcam#remoteVideo").height(($( window ).height()-61-80-10)/3*2);
$(".webcam#localVideo").height(($( window ).height()-61-80-10)/3);
whois = whoismobile;
mobilesize = 1;
if($('.messageinput[data-id="' + iud + '"]').is(":focus"))
scrolldown(2);
} else {
if(type == "chatroom")
var moreheigth = -34;
else
var moreheigth = 0;
if(adsonsee == 0)
showadsplace();
var lolheighter = $("#jatti").height();
whois = whoisdesktop;
mobilesize = 0;
if($( window ).height() < 600) {
$(".chatblock .chat-window").height(($( window ).height()-165));
$(".webcam#remoteVideo, .webcam#localVideo").height(($( window ).height()-165)/2);
} else if($( window ).height() < 769) {
$(".chatblock .chat-window").height(($( window ).height()-200-moreheigth-lolheighter-3));
$(".webcam#remoteVideo, .webcam#localVideo").height(($( window ).height()-200-moreheigth-lolheighter-3)/2);
} else {
$(".chatblock .chat-window").height(($( window ).height()-250-moreheigth-lolheighter-3));
$(".webcam#remoteVideo, .webcam#localVideo").height(($( window ).height()-250-moreheigth-lolheighter-3)/2);
}
}
}
setTimeout(function() {
if(type == "chatroom")
$(".chatblock2 .chat-window").height($(".chatblock").height());
},200);
tabmiz();
}
var activewin = 1;
var activetype = 1;
$(window).resize(function() {
winresize();
});
$(window).focus(function() {
activewin = 1;
msgcount = 0;
cancelFlashTitle(timeout);
if(type == "chatroom") {
$.post("//panettaa.org/handler.php", {
update : type,
uid : userid[0],
activeuser: 1
});
}
});
$(window).blur(function() {
activewin = 0;
});
function intervalTrigger() {
return window.setInterval( function() {
var isactive = 0;
if(activewin == 1)
isactive = 1;
activetype = 0;
$.post("//panettaa.org/handler.php", {
update : type,
uid : userid[0],
activeuser: isactive
})
.done(function (data) {
$(".onlinecount").html(data);
});
//ga('send', 'event', 'Chat', 'Online', type);
_gaq.push(['_trackEvent', 'Chat', 'Online', type]);
}, 45000 );
};
function endbuttons(beforesd) {
var endbtn = "";
endbtn = endbtn + ' ';
return endbtn;
}
function setsets() {
if(localStorage.notifications == undefined) {
localStorage.notifications = 0;
}
if(localStorage.notifications == 1) {
$.notification.requestPermission(function () {});
$(".not input").attr("checked", true);localStorage.notifications = 1;
}
if(localStorage.sounds == 1 || localStorage.sounds == undefined) {
$(".sou input").attr("checked", true);localStorage.sounds = 1;
}
if(localStorage.pics == 1 || localStorage.pics == undefined) {
$(".pics input").attr("checked", true);localStorage.pics = 1;
}
if(localStorage.gifs == 1 || localStorage.gifs == undefined) {
$(".gifs input").attr("checked", true);localStorage.gifs = 1;
}
if(localStorage.shortcuts == 1 || localStorage.shortcuts == undefined) {
$(".sho input").attr("checked", true);localStorage.shortcuts = 1;
} else {
$(".shortcut").hide();
}
}
function setnotifications() {
if(localStorage.notifications == 1) {
localStorage.notifications = 0;
$(".not input").attr("checked", false);
} else {
$.notification.requestPermission(function () {});
localStorage.notifications = 1;
$(".not input").attr("checked", true);
}
}
function setsounds() {
if(localStorage.sounds == 1) {
localStorage.sounds = 0;
$(".sou input").attr("checked", false);
} else {
localStorage.sounds = 1;
$(".sou input").attr("checked", true);
}
}
function setpics() {
if(localStorage.pics == 1) {
localStorage.pics = 0;
$(".pics input").attr("checked", false);
} else {
localStorage.pics = 1;
$(".pics input").attr("checked", true);
}
}
function setgifs() {
if(localStorage.gifs == 1) {
localStorage.gifs = 0;
$(".gifs input").attr("checked", false);
} else {
localStorage.gifs = 1;
$(".gifs input").attr("checked", true);
}
}
function setshortcuts() {
if(localStorage.shortcuts == 1) {
localStorage.shortcuts = 0;
$(".sho input").attr("checked", false);
$(".shortcut").hide();
} else {
localStorage.shortcuts = 1;
$(".sho input").attr("checked", true);
$(".shortcut").show();
}
}
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function gusers() {
if(roomid[0] != undefined && chaton == 1) {
$.post("//panettaa.org/handler.php", {
users : type,
rid: roomid[0]
})
.done(function (data) {
if(data != "[]" && data != "") {
gid = JSON.parse(data);
$(".gonline").show();
$(".gcount").html(Object.size(gid));
} else {
setTimeout(gusers,1000);
}
});
}
}
function roomusers() {
if(roomid[0] != undefined) {
$.post("//panettaa.org/handler.php", {
users : type,
rid: roomid[0],
all: true
})
.done(function (data) {
if(data != "[]" && data != "") {
gid = JSON.parse(data);
$.each( gid, function( key, value ) {
var datauser = value.split(";;");
gid[key] = datauser;
});
gids = JSON.parse(data);
var lists = "";
var glist = {};
var addedusers = [];
var afk = '[AFK] ';
$.each( gids, function( key, value ) {
var datauser = value.split(";;");
if(gids[0] != undefined)
$(".gonline").addClass("hidden-xs").html(gids[0].split(";;")[0]).show();
if(datauser[6] == "0") {
gids[key] = datauser;
if(addedusers.indexOf(datauser[0]) == -1) {
addedusers.push(datauser[0]);
gidusers[datauser[1]] = datauser;
var ihtml = "";
if(datauser[2] == "2") {
var modlevel = "@";
var modclass = "admin";
} else if(datauser[2] == "1") {
var modlevel = "+";
var modclass = "moderator";
} else {
var modlevel = "";
var modclass = "";
}
if(Object.keys(points).length > 0) {
if(points[datauser[0]] == undefined)
points[datauser[0]] = 0;
var pointshtml = " (" + points[datauser[0]] + "p.) ";
} else
var pointshtml = "";
if(datauser[8] == "1")
pointshtml += afk;
if(datauser[1] == 0)
datauser[1] = key;
glist[modlevel + datauser[0].toLowerCase()] = ' ' + modlevel + '' + datauser[0] + '' + pointshtml + ' ' + ihtml + ' ';
}
} else {
delete gids[key];
}
});
lists = '' + Object.keys(addedusers).length + ' chatissa ';
Object.keys(glist)
.sort(function keyOrder(k1, k2) {
if (k1 < k2) return -1;
else if (k1 > k2) return +1;
else return 0;
})
.forEach(function(v, i) {
lists += glist[v];
});
$(".userlist").html('');
} else {
setTimeout(roomusers,1000);
}
});
}
}
function htmlencode(str) {
return str.replace(/[&<>"']/g, function($0) {
return "&" + {"&":"amp", "<":"lt", ">":"gt", '"':"quot", "'":"#39"}[$0] + ";";
});
}
var latestgmsg1 = "";
var latestgmsg2 = "";
var videointi;
function newmsg(msg, roomv, who, notime,groupid,typ,nosound,prepend,scroll) {
if(type == "chatroom" || type == "group" || (startingtime+30) < moment().unix() || (msg.indexOf("https://giphy.com/gifs/") != -1 || msg.indexOf("https://media.giphy.com/media/") != -1) || (msg.toLowerCase().indexOf("www.") === -1 && msg.toLowerCase().indexOf("http") === -1 && ((who == "1" && msgcounter > 1) || typ !== 1 || othermsgcounter > 1)))
if((msg.length < 450 || who != 2) && (latestgmsg1 != msg || latestgmsg2 != groupid)) {
latestgmsg1 = msg;
latestgmsg2 = groupid;
var roomis = roomid.indexOf(roomv);
if(roomv == undefined)
roomis = 0;
if(roomis != 0 || (type != "group" && type != "chatroom") || ((type == "group" && ignoredusers.indexOf(groupid) == -1) || (groupid != undefined && type == "chatroom" && ignoredusers.indexOf(groupid[4]) == -1))) {
clearTimeout(status);
newstatus_active = 0;
if(who == "1") {
msg = htmlencode(msg);
} else if(who == "2")
othermsgcounter++;
if(typ == undefined || typ == 0) {
if(type == "chatroom") {
var regforthis = RegExp('(^| |[^\/>]^.)('+localStorage.username+')(|$)','g');
msg = msg.replace(regforthis, ' '+localStorage.username+' ');
}
if(typeof emojione !== "undefined")
msg = emojione.toImage(msg);
if(msg.indexOf("**") !== 1)
msg = markuptext(msg,"**","b");
if(msg.indexOf("__") !== 1)
msg = markuptext(msg,"__","u");
if(msg.indexOf("\\\\") !== 1)
msg = markuptext(msg,"\\\\","i");
if(msg.indexOf("~~") !== 1)
msg = markuptext(msg,"~~","s");
msg = linkifyHtml(msg,{target: "_blank"});
}
if(who == 2 && roomis == 0) {
said = 1;
}
if($('.messageinput[data-id="' + roomis + '"]').is(":focus")) {
socket.emit('meta', { room: roomid[roomis], user: userid[roomis], data: { readed: true } });
//$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + roomis});
}
$('.statusline[data-id="' + roomis + '"]').hide();
$('.statusline[data-id="' + roomis + '"]').html('');
$('.chat-window[data-id="' + roomis + '"] .chatdata li.forstatus').remove();
if(groupid != 0 && groupid != "" && groupid != undefined && type != "chatroom") {
var oldgroupid = groupid;
groupid = groupid;
} else if(groupid != 0 && groupid != "" && groupid != undefined) {
var oldgroupid = groupid[0];
var groupid2 = groupid[5];
groupid = groupid[0];
} else {
groupid = "";
}
if(roomis != 0) {
if($('.chat[data-id="' + roomis + '"]').length == 0) {
openchat(roomis);
setTimeout(function() { newmsg(msg, roomv, 2, notime,groupid,typ,nosound,prepend,scroll); },1000);
return;
}
if($('.chat[data-id="' + roomis + '"] .messageinput').is(":focus") && who != 1)
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + roomis});
if(who != 1 && $(".chat" + roomis + ":hidden").length == 0)
$(".chat" + roomis + " .minichatbtn").removeClass("btn-default").addClass("btn-success");
else if(who != 1)
$(".moretab.left").removeClass("btn-default").addClass("btn-success");
} else {
if(type == "video" && who == 2 && !$(".chatblock").hasClass("open"))
videointi = setInterval(function(){
$(".showchat").addClass("btn-primary").removeClass("btn-success");
setTimeout(function(){$(".showchat").removeClass("btn-primary").addClass("btn-success"); },1000);
}, 2000);
}
var whoo = who;
if(notime > 1)
time = '' + moment(notime).format("H:mm") + ' - ';
else if(notime != 1)
time = '' + moment().format("H:mm") + ' - ';
else
time = "";
if (who == undefined || who == 0) {
who = "";
whoe = " ";
} else {
if((roomis == 0 || who != 2) && type == "group")
who = '' + groupid + ': ';
else if((roomis == 0 || who != 2) && type != "chatroom")
who = '' + whois[who] + groupid + ': ';
else if(roomis == 0 && type == "chatroom" && groupid != "")
who = '' + groupid2 + ': ';
else if(who == 1 && type == "chatroom")
who = '' + whois[who] + ': ';
else
who = '' + users[roomis][2] + ': ';
if(type == "group" && oldgroupid != 0 && whoo != 1)
who = who + ' ';
whoe = "";
}
if(typ != undefined && typ != 0) {
if(typ == 1 && localStorage.pics == 1) {imageadd = true;
msg = ' ';
} else if(typ == 1) {
msg = 'Kuva (Katso klikkaamalla) ';
}
else if(typ == 2 && localStorage.pics == 1) {imageadd = true;
msg = ' ';
} else if(typ == 2) {
msg = 'Piirros (Katso klikkaamalla) ';
}
else if(typ == 11 && localStorage.pics == 1 && msg != "error") {
msg = ' . ';
} else if(typ == 11 && msg != "error") {
msg = 'Video (Katso klikkaamalla) ';
}
else if(typ == 9 && localStorage.pics == 1) {imageadd = true;
msg = ' ';
} else if(typ == 9) {
msg = ' (Katso klikkaamalla) ';
}
else if(type != "chatroom" && type != "group" && typ == 3 && localStorage.bigroom == roomis) {
msg = msg + ' ';
}
else if(type != "chatroom" && type != "group" && typ == 3 && localStorage.bigroom != roomis) {
msg = msg + ' ';
}
else if(type != "chatroom" && type != "group" && typ == 4 && localStorage.bigroom == roomis) {
answerwebcam(1,openid);
}
else if(type != "chatroom" && type != "group" && typ == 4 && localStorage.bigroom != roomis) {
msg = msg + ' Avaa videopuheluikkuna ';
}
else if(typ == 5) {
closewebcam(1);
}
else if(type != "chatroom" && type != "group" && typ == 6) {
msg = msg + ' ';
}
else if(typ == 7) {
$(".askfriend").parent().remove();
}
else if(typ == 8) {
keepactive = 1;
}
}
if(localStorage.gifs == 1 && (msg.indexOf("https://giphy.com/gifs/") != -1 || msg.indexOf("https://media.giphy.com/media/") != -1)) {
if(msg.indexOf("https://giphy.com/gifs/") != -1) {
var gifmsg = msg.split("https://giphy.com/gifs/")[1];
gifmsg = gifmsg.split("-")[gifmsg.split("-").length-1].split('"')[0];
var gifurl = "https://giphy.com/gifs/" + msg.split("https://giphy.com/gifs/")[1].split('"')[0];
} else {
var gifmsg = msg.split("https://media.giphy.com/media/")[1];
gifmsg = gifmsg.split('/')[0];
var gifurl = "https://media.giphy.com/media/" + msg.split("https://media.giphy.com/media/")[1].split('giphy.gif')[0] + "giphy.gif";
}
var re22 = new RegExp(gifurl, 'g');
msg = msg.replace(re22,"");
if(gifmsg != "QVJIApBKOzzIFQxLy1") {
giphy.gif({
id: gifmsg,
rating: 'r',
fmt: 'json'
},
function(data) {
data = data.data;
$("." + data.id).html('');imageadd = true;
scrolldown(1,roomis);
});
msg = ' ' + msg;
}
}
var chatlines = document.getElementById("chatlines");
var e = document.createElement("li");
e.className = "chat-line oldline";
e.setAttribute("data-user", groupid);
e.innerHTML = '' + time + '' + who + ' ' + msg + '' + whoe + '';
if(prepend != 1)
chatlines.appendChild(e);
else
chatlines.insertBefore(e,chatlines.firstChild);
if(whoo != 1 && nosound != 1 && notime < 2) {
scrolldown(1,roomis);
} else if((nosound != 1 || notime > 1) && scroll != 1) {
scrolldown(2,roomis);
}
if(whoo != 1 && !activewin && nosound != 1) {
if(roomis != 0 && mobilesize && iud != roomis) {
$(".navbar-toggle").addClass("unreaded");
$(".friends-toggle").addClass("unreaded");
friendmenu(1);
setTimeout(function() {friendmenu(1)},15000);
}
msgcount = msgcount+1;
if(localStorage.sounds == 1)
msound.play();
if(roomis == 0 && type == "chatroom")
var nick = groupid;
else if(roomis == 0)
var nick = "Seurasi";
else
var nick = username[roomis];
if(msgcount == 1) {
var titlemsg = '(' + msgcount + ') ' + nick + ' (' + msgcount + " uusi viesti)";
var titlemsg2 = msgcount + " uusi viesti";
} else {
var titlemsg = '(' + msgcount + ') ' + nick + ' (' + msgcount + " uutta viestiä)";
var titlemsg2 = msgcount + " uutta viestiä";
}
if(localStorage.notifications == 1 && (localStorage.lnotification == undefined || localStorage.lnotification != who + msg)) {
localStorage.lnotification = who + msg;
var lolmsg = '' + who + ' ' + msg + '' + whoe + '';
lolmsg = lolmsg.replace(/<(?:.|\n)*?>/gm, '');
var options = {
iconUrl: '//panettaa.org/images/tlogo.png',
title: titlemsg2,
body: lolmsg,
timeout: 3000, // close notification in 1 sec
onclick: function () {
}
};
var notification = $.notification(options);
}
flashTitle(titlemsg);
}
}
}
}
function gonline() {
var lists = "";
if($(".gonline").hasClass("open")) {
$(".gmore").slideUp();
$(".gonline").removeClass("open");
} else {
$(".gmore").html("Chatissa ");
$.each( gid, function( key, value ) {
if(ignoredusers.indexOf(value) != -1)
var ihtml = ' ';
else
var ihtml = ' ';
lists = lists + ""+ value +"" + ihtml + " ";
});
$(".gmore").append("");
$(".gmore").slideDown();
$(".gonline").addClass("open");
}
}
var scrolltimer;
var scrollon = false;
var scrollon2 = false;
$('.chat-window[data-id="0"]').scroll(function() {
if(!scrollon2) {
scrollon = true;
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
scrollon = false;
}, 400));
}
});
var imageadd = false;
function scrolldown(downtype,roomv) {
if(roomv == undefined || roomv == "" || roomv == -1) {
roomv = 0;
}
if($('#chatwindow' + roomv + '').scrollTop() + $('#chatwindow' + roomv + '').height() >= $('#chatwindow' + roomv + ' .chatdata').height()-250)
var down = 1;
else
var down = 0;
if((down == 1 && !scrollon) || downtype == 2) {
if(imageadd) {
imagesLoaded($('#chatwindow' + roomv + ' li:gt(-6)'), function() { imageadd = false;
$('#chatwindow' + roomv + '').scrollTop($('#chatwindow' + roomv + '')[0].scrollHeight);
});
} else {
$('#chatwindow' + roomv + '').scrollTop($('#chatwindow' + roomv + '')[0].scrollHeight);
}
scrollon2 = true;
setTimeout(function() {
scrollon2 = false;
}, 200);
//nottop = 0;
} else if(downtype == 1 && $('#chatwindow' + roomv + '').scrollTop() + $('#chatwindow' + roomv + '').height() < $('#chatwindow' + roomv + ' .chatdata').height()-250) {
$('.chatwindow-info[data-id="' + roomv + '"]').html('uusi viesti
').removeClass("hided");
nottop = 1;
}
}
$( ".chat-window" ).scroll(function() {
var roomv = 0;
if(nottop == 1) {
if($('#chatwindow' + roomv + '').scrollTop() + $('#chatwindow' + roomv + '').height() == $('#chatwindow' + roomv + ' .chatdata').height()) {
$('.chatwindow-info[data-id="' + roomv + '"]').html('').addClass("hided");
nottop = 0; }
}
});
function downscroll(roomv) {
document.getElementById('chatwindow' + roomv + '').lastElementChild.scrollIntoView(false);
nottop = 0;
setTimeout(function() { $('.chatwindow-info[data-id="' + roomv + '"]').html('').addClass("hided"); },200);
}
var newstatus_active = 0;
function newstatus(msg,room) {
if(newstatus_active == 0) {
var statushtml = document.getElementById("statusline");
setTimeout(function() { newstatus_active = 0; },500);
clearTimeout(status);
var roomis = roomid.indexOf(room);
if(statushtml.innerHTML != '' + msg + ' ') {
statushtml.style.display = "block";
statushtml.innerHTML = '' + msg + ' ';
if($('.chat-window[data-id="' + roomis + '"] .chatdata .forstatus').length == 0) {
$('.chat-window[data-id="' + roomis + '"] .chatdata').append(' ');
newstatus_active = 1;
scrolldown(0,roomis);
}
}
status = setTimeout(function() {
statushtml.style.display = "none";
statushtml.innerHTML = '';
if(roomis != 0)
$(".chatdata li.forstatus").remove();
}, 1500);
}
}
var adsonsee = 0;
function showadsplace() {
$("iframe#taaontaa").prop("src", function(){
return $(this).data("src");
});
adsonsee = 1;
}
function search(types) {
if(!mobilesize)
showadsplace();
if(userid[0] != undefined && userid[0] != "" && location.hash != "#disconnected" && chattypes.indexOf(hashdata[0].substring(1)) !== -1) {
startchat(roomid[0]);
} else {
type = types;
chatintype = types;
//ga('send', 'event', 'Chat', 'Search', type);
_gaq.push(['_trackEvent', 'Chat', 'Search', type]);
if(type == "match") {
if(localStorage.psex != undefined && localStorage.psex != "") {
$.post("//panettaa.org/handler.php", {
add : type,
msex : localStorage.msex,
mage : localStorage.mage,
mstate : localStorage.mstate,
mcity : localStorage.mcity,
psex : localStorage.psex,
pmaage : localStorage.pmaxage,
pmiage : localStorage.pminage,
pstate : localStorage.pstate,
pcity : localStorage.pcity
})
.done(function (data) {
userid[0] = data;
if(!mobilesize || is_vip)
searchpartner();
else
searchpartner(7000);
});
} else {
location.href = "//panettaa.org/täsmät-match.html";
}
} else if(type == "video") {
if(isIEorEDGE()) {
bootbox.alert("Valitettavasti videochat ei toimi Internet Explorerilla tai Edge-selaimella. Videochat toimii parhaiten Google Chromella.");
} else {
isPrivate(
function () { bootbox.alert("Virhe");}
,
function () {
var htmlcode = '';
htmlcode += '
Olen ';
htmlcode += 'mies nainen
';
htmlcode += '
Haen ';
htmlcode += 'molempia miehiä naisia
';
$(".blackvideo").show();
bootbox.dialog({
message: htmlcode,
title: "",
buttons: {
danger: {
label: "Peruuta",
className: "btn-danger pull-left",
callback: function() {
location.href = "/";
}
},
success: {
label: "Jatka",
className: "btn-success",
callback: function() {
localStorage.msex = $(".iam").val();
localStorage.psex = $(".isearch").val();
$.post("//panettaa.org/handler.php", {
add : type,
msex: localStorage.msex,
psex: localStorage.psex
})
.done(function (data) {
if(data == "toomany") {
$(".chatdata").html('Liian monta hakua auki! Sinulla on auki liian monta ikkunaa haussamme tästä osoitteesta!
');
} else if(data.indexOf("{") == -1) {
userid[0] = data;
searchpartner();
$(".chatblock").addClass("hidden-xs mobilevideo");
$(".chatinputs").addClass("mobilevideoinputs mobilevideoinputsvisi");
$("#remoteVideo").html('Etsitään seuraa... ');
} else {
var data = JSON.parse(data);
$(".chatdata").html('Olet saanut porttikiellon! Syy: ' + data.reason + '
Porttikielto loppuu: ' + data.ended + '
');
}
});
}
}
}
}); });
}
} else if(type == "chatroom") {
if(
(localStorage.username != "" && localStorage.username != undefined) ||
location.pathname.substring(location.pathname.lastIndexOf("/") + 1).slice(0,-5) == "Hissi"
) {
if(location.pathname.substring(location.pathname.lastIndexOf("/") + 1).slice(0,-5) == "Hissi") {
var rusername = Math.random().toString(36).substr(2);
} else {
localStorage.username = localStorage.username.replace("'",'');
localStorage.username = localStorage.username.replace("?",'');
var rusername = localStorage.username;
}
$.post("//panettaa.org/handler.php", {
add : type,
uid : rusername,
rid : location.pathname.substring(location.pathname.lastIndexOf("/") + 1).slice(0,-5)
})
.done(function (data) {
if(data.indexOf("{") == -1) {
if(data == "nickused") {
bootbox.prompt("Kyseinen nimi on jo käytössä. Valitse Käyttäjätunnus", function(result) {
if (result === null) {
} else {
localStorage.username = result;
search(type);
}
});
} else {
var datad = data.split(",");
userid[0] = datad[0];
roomid[0] = datad[1];
startchat(datad[1]);
}
} else {
var data = JSON.parse(data);
$(".chatdata").html('Olet saanut porttikiellon! Syy: ' + data.reason + '
Porttikielto loppuu: ' + data.ended + '
');
}
});
} else {
bootbox.prompt("Valitse Käyttäjätunnus", function(result) {
if (result === null) {
} else {
localStorage.username = result;
search(type);
}
});
}
} else {
if(localStorage.tags2 != "" && localStorage.tags2 != undefined)
var tagers = localStorage.tags2;
else
var tagers = "";
$.post("//panettaa.org/handler.php", {
add : type,
tags: tagers
})
.done(function (data) {
if(data.indexOf("{") == -1) {
userid[0] = data;
searchpartner();
if(type == "video") {
$(".chatblock").addClass("hidden-xs mobilevideo");
$(".chatinputs").addClass("mobilevideoinputs mobilevideoinputsvisi");
$("#remoteVideo").html('Etsitään seuraa... ');
}
} else {
var data = JSON.parse(data);
$(".chatdata").html('Olet saanut porttikiellon! Syy: ' + data.reason + '
Porttikielto loppuu: ' + data.ended + '
');
}
});
}
}
}
function sendmsg(usid) {
if(inputs[0] == undefined) {
inputs[0] = 0;
spams[0] = 0;
}
var kid = 0;
clearTimeout(inputs[kid]);
inputs[kid] = setTimeout(function(){ spams[kid] = 0; }, 2000);
spams[kid] = spams[kid]+1;
if(spams[kid] <= 5) {
var msg = $('.messageinput[data-id="' + usid + '"]').val().trim();
if (msg != "" && msg != lastmsg) {
lastmsg = msg;
$('.messageinput[data-id="' + usid + '"]').val("").focus();
msgcounter++;
if(msgcounter < 3 && type == "normal" && tps.indexOf(msg.toLowerCase()) !== -1) {
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'addtp=1&userid=' + userid[usid]});
}
if(msgcounter < 3 && type == "normal" && msg.toLowerCase().indexOf(tpsblack) !== -1) {
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'addtp=2&userid=' + userid[usid]});
}
if(msg.indexOf(blacklistwords) !== -1) {
newmsg(msg, roomid[usid], 1,0);
return false;
}
if(type == "chatroom" || (startingtime+30) < moment().unix() || (msg.toLowerCase().indexOf("addslut") === -1 && msg.toLowerCase().indexOf("ellajuuliaaa") === -1 && msg.toLowerCase().indexOf("www.") === -1 && msg.toLowerCase().indexOf(".club") === -1 && msg.toLowerCase().indexOf("http") === -1 && msg.toLowerCase().indexOf(".com") === -1))
socket.emit('message', { room: roomid[usid], user: userid[usid], message: msg }, function(err) { if(err){ console.error(err);
if(type == "chatroom" && err.code == "NOT_IN_ROOM")
startchat(roomid[usid]);
$('.messageinput[data-id="' + usid + '"]').val(lastmsg).focus(); }});
if(type == "group" || type == "chatroom") {
if(gid[userid[usid]] == undefined) {
gid[userid[usid]] = userid[usid].substring(1, 4);
}
newmsg(msg, roomid[usid], 1,0,gid[userid[usid]]);
} else
newmsg(msg, roomid[usid], 1,0);
$('.chat[data-id="' + usid + '"] textarea').trigger('autosize.resize');
if($('.messageinput[data-id="' + usid + '"]').height() != messageheight) {
setTimeout(function() {
messageheight = $('.messageinput[data-id="' + usid + '"]').height();
$('.chat[data-id="' + usid + '"] .btn').height($('.chat[data-id="' + usid + '"] textarea').height());
},50);
}
if(usid != 0)
$.ajax({type: 'POST',url: "//panettaa.org/handler.php",data: 'readed=' + iud});
}
} else {
newstatus("Hidastas vähän, spämmi on kielettyä.",roomid[usid]);
}
}
function gettagsoff() {
localStorage.tags2 = "";
location.reload();
}
function getbg(usid) {
/*
$.post("//panettaa.org/handler.php", {
bg : type,
uid : userid[usid],
rid: roomid[usid]
})
.done(function (data) {
if(data != "" && data != "src/bgs/") {
$("body").css('background-image', 'url(//panettaa.org/' + data + ')');
$(".navbar-header").css('background-image', 'url(//panettaa.org/' + data + ')');
}
});*/
}
var videoblacktimer;
var chatblacktimer;
function searchpartner(waiting) {
if(waiting == undefined)
waiting = 0;
if(type == "match" && mobilesize && !is_vip) {
$('.chat-window[data-id="0"] .chatdata').html('
Etsitään seuraa Ilmoitamme sinulle kun kriteeriesi mukainen seura löytyy.
');
} else {
$('.chat-window[data-id="0"] .chatdata').html('Etsitään seuraa... Ilmoitamme sinulle kun kriteeriesi mukainen seura löytyy.
');
}
if(!is_vip)
$(".searching").append('Onko seuran löytyminen hidasta? VIP-koodilla löydät nopeammin! ');
if(localStorage.tags2 != undefined && localStorage.tags2.length > 0 && type == "normal")
$(".searching").append('Käytät aiheita: ' + localStorage.tags2 + 'Voit kytkeä ne pois tästä ');
if(type == "video") {
$("#remoteVideo").html('Etsitään seuraa... ');
winresize();
}
if(localStorage.shortcuts != 1)
var hide = 'style="display:none;"';
else
var hide = "";
$(".disconnect").addClass("btn-danger").removeClass("btn-success").html(' Katkaise (ESC) ');
chatblacktimer = setTimeout(function() { $.post("//panettaa.org/handler.php", {
search : type, uid : userid[0]
})
.done(function (data) {
if(data != "" || data.length < 2000) {
startchat(data);
if(type == "video") {
clearInterval(videoblacktimer);
}
}
})
.fail(function (data) {
if(disconnected == 0) {
searchpartner();
}
});
},waiting);
}
var startingtime = 0;
function startchat(data) {
$(".disconnect").removeClass("sure");
if (data != undefined && data != "left" && data != "") {
if(type != "chatroom")
$( ".menuitem, .navbar a" ).attr( "target", "_blank" );
//ga('send', 'event', 'Chat', 'Start', type);
_gaq.push(['_trackEvent', 'Chat', 'Start', type]);
socket.emit('join', { room: data, user: userid[0] }, function(err) {
if(err) {
if(type == "video") {
$("#remoteVideo").html('Huonetta ei löydy ');
}
console.error(err);
location.hash = "error";
$(".chatdata").html("");
newmsg("Huonetta ei löydy",roomid[0],0,1);
disconnect(2);
} else {
startingtime = moment().unix();
roomid[0] = data;
if(type != "chatroom") {
location.hash = type + "/" + data + "/" + userid[0];
chaton = 1;
} else {
roomusers();
setTimeout(getroommessages,500);
}
if(type == "video") {
$(".blackvideo").attr("disabled",false);
clearTimeout(breporttime);
$("#remoteVideo").html('');
$(".pausewebcam, .pausewebcam2").toggle();
setTimeout(function() { webrtc.joinRoom(roomid[0]); },500);
} else if(type == "match") {
$.post("//panettaa.org/handler.php", {
getinfo : 1,
user : userid[0],
room : roomid[0]
}).done(function (data) {
$(".gonline").html(data.age + 'v ' + data.sex + ' ' + data.state + ', ' + data.city + '').show();
});
}
var roomis = roomid.indexOf(data);
if(type == "group")
gusers();
disconnected = 0;
$('.chat-window[data-id="' + roomis + '"] .chatdata').html("");
newmsg("Seura löytyi, sano moi!", data);
$(".chatinputs textarea, .chatinputs input, .chatinputs button, #addfriends, #reportuser").removeAttr('disabled');
if(type == "group")
$("#addfriends").attr("disabled",true);
updating = intervalTrigger();
if(type != "group" && type != "chatroom")
getbg(userid[iud]);
$('.messageinput[data-id="0"]').focus();
}
});
} else {}
if(type == "group") {
gusers();
setTimeout( function() { gids = gid; },4000);
}
}
//FF ANDROID SUUPORT
if(/Android.+Firefox\//.test(navigator.userAgent)) {
var ffandroid = "input ";
} else {
var ffandroid = "";
}
var getKeyCode = function (str) {
return str.charCodeAt(str.length - 1);
}
if(/Android/.test(navigator.userAgent)) {
$( ".messageinput" ).bind("keyup",function( event ) {
if (event.keyCode == 0 || event.keyCode == 229) { //for android chrome keycode fix
event.keyCode = getKeyCode(this.value);
}
if(!event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) ) {
if($(this).val() != "") {
$("#chatsendbtn").click();
/*sendmsg(uid);
$(this).val(""); */
}
if(!(navigator.userAgent.match(/iemobile/i)))
event.preventDefault();
}
});
}
$( ".messageinput" ).bind(ffandroid + "paste keydown",function( event ) {
if($(this).data("id") != "")
var uid = $(this).data("id");
else
var uid = 0;
if(!event.ctrlKey && event.keyCode == 13) {
if($(this).val() != "") {
$("form.chatinputs").submit();
/*sendmsg(uid);
$(this).val(""); */
}
if(!(navigator.userAgent.match(/iemobile/i)))
event.preventDefault();
//$('.chat[data-id="' + uid + '"] textarea').trigger('autosize.resize');
} else {
if(write == 0) {
socket.emit('meta', { room: roomid[uid], user: userid[uid], data: { typing: true } });
if(!ismobile && type == "chatroom" && gid[userid[0]] != undefined)
$(".user" + gid[userid[0]][1] + " .afk").remove();
write = 1;
setTimeout(function() { write = 0; },1000);
}
}
if($(this).height() != messageheight) {
setTimeout(function() {
messageheight = $(".messageinput").height();
$('.chat[data-id="' + uid + '"] .btn').height($('.chat[data-id="' + uid + '"] textarea').height());
},50);
}
});
socket.on('message', function (data) {
data.message = htmlencode(data.message);
if(userid.indexOf(data.user) == -1) {
var roomis = roomid.indexOf(data.room);
if(roomis == 0 && (type == "group" || type == "chatroom")) {
if(type == "group" && gid[data.user] == undefined && validateCode(data.user)) {
gid[data.user] = data.user.substring(1, 4);
}
if(inputs[data.user] == undefined) {
inputs[data.user] = 0;
spams[data.user] = 0;
}
var kid = data.user;
clearTimeout(inputs[kid]);
inputs[kid] = setTimeout(function(){ spams[kid] = 0; }, 2000);
spams[kid] = spams[kid]+1;
if(spams[kid] <= 5) {
if( gid[data.user] != undefined && validateCode(data.user)) {
if(data.meta != undefined)
newmsg(data.message,data.room,2,0,gid[data.user],data.meta.type);
else
newmsg(data.message,data.room,2,0,gid[data.user]);
}
}
} else if(latestmsg != data.message) {
latestmsg = data.message;
if(data.meta != undefined) {
if(data.meta.time != undefined)
newmsg(data.message,data.room,0,0,0,data.meta.type);
else
newmsg(data.message,data.room,2,0,0,data.meta.type);
} else
newmsg(data.message,data.room,2,0,0);
}
} else {
if(lastmsg != data.message) {
var roomis = roomid.indexOf(data.room);
if(roomis != 0) {
if(data.meta != undefined) {
if(data.meta.time == undefined)
newmsg(data.message,data.room,1,0,0,data.meta.type);
} else
newmsg(data.message,data.room,1,0,0);
}
}
}
});
socket.on('meta', function (data) {
if(userid.indexOf(data.user) == -1) {
var roomis = roomid.indexOf(data.room);
if(roomis != 0 || (type != "group" && type != "chatroom") || ((type == "group" && ignoredusers.indexOf(gid[data.user]) == -1) || (type == "chatroom" && ignoredusers.indexOf(data.user.substring(1, 4)) == -1))) {
if(type == "group" && gid[data.user] == undefined)
gusers();
if(type == "chatroom" && gid[data.user] == undefined)
roomusers();
if(data.data.typing != undefined) {
if(type == "group" && gid != undefined && gid[data.user] == undefined && validateCode(data.user)) {
gid[data.user] = data.user.substring(1, 4);
}
if(type == "group" && gid != undefined && gid[data.user] != "" && gid[data.user] != undefined)
data.data.groupid = gid[data.user];
else if(type == "chatroom" && gid != undefined && gid[data.user] != "" && gid[data.user] != undefined)
data.data.groupid = gid[data.user][0];
else
data.data.groupid = "";
if(type == "chatroom") {
if( gid != undefined && gid[data.user] != "" && gid[data.user] != undefined && gid[data.user][8] == "1")
if(gid[data.user][1] != "0")
$(".user" + gid[data.user][1] + " .afk").remove();
else
$(".user" + data.user + " .afk").remove();
}
if(validateCode(data.user)) {
if(roomis == 0 && type != "group" && type != "chatroom")
newstatus('Seurasi kirjoittaa...',data.room);
else if(roomis == 0 && type != "chatroom")
newstatus(data.data.groupid + ' kirjoittaa...',data.room);
else if(roomis == 0 && type == "chatroom") {
if(data.data.groupid != "")
newstatus(data.data.groupid + ' kirjoittaa...',data.room);
} else {
newstatus( username[roomis] + ' kirjoittaa...',data.room);
}
}
} else if(data.data.kicked != undefined && type == "chatroom") {
addusertokicked(data.data.kicked,data.user);
}
}
} else if(data.data.readed != undefined) {
var roomis = roomid.indexOf(data.room);
$(".chat" + roomis + " .minichatbtn").addClass("btn-default").removeClass("btn-success");
$('.friendlist .newmsg[data-id="' + roomis + '"]').removeClass("newmsg");
if($('.friendlist .newmsg').length == 0) {
$('.menubutton').removeClass("btn-success").addClass("btn-default");
$(".navbar-toggle").removeClass("unreaded");
$(".friends-toggle").removeClass("unreaded");
document.title = original;
}
}
});
var lastparted = 0;
socket.on('part', function (data) {
var roomis = roomid.indexOf(data.room);
if((type == "group" || type == "chatroom" || data.user != userid[roomis]) && roomis == 0) {
if(type == "group") {
if(gid[data.user] != lastparted) {
if(gids[data.user] != undefined) {
newmsg('' + gids[data.user] + ' lähti',data.room,0,0);
setTimeout( function() { gusers(); },1000);
} else if(gid[data.user] != undefined) {
newmsg('' + gid[data.user] + ' lähti',data.room,0,0);
setTimeout( function() { gusers(); },1000);
}
}
lastparted = gid[data.user];
} else if(type == "chatroom") {
if(gids[data.user] != undefined) {
newmsg('' + gids[data.user][0] + ' lähti',data.room,0,0);
setTimeout( function() { roomusers(); },1000);
} else if(gid[data.user] != undefined) {
newmsg('' + gid[data.user][0] + ' lähti',data.room,0,0);
setTimeout( function() { roomusers(); },1000);
}
} else {
if(data.reason == "disconnected") {
if(dcount >= 0)
newmsg('Seuraltasi katkesi yhteys. Voit odottaa paluuta, jos haluat.',data.room,0,1);
dcount = dcount+1;
} else {
disconnect(1);
disconnected = 1;
}
}
}
});
socket.on('join', function (data) {
var roomis = roomid.indexOf(data.room);
if((type == "group" || type == "chatroom" || data.user != userid[roomis]) && roomis == 0) {
if(type == "group") {
gusers();
if(gid[data.user] != undefined) {
newmsg('' + gid[data.user] + ' liittyi',data.room,0,0);
} else {
setTimeout(function() { gusers();
if(gid[data.user] != undefined) {
newmsg('' + gid[data.user] + ' liittyi',data.room,0,0);
} else {
setTimeout(function() {
gusers();
if(gid[data.user] != undefined) {
newmsg('' + gid[data.user] + ' liittyi',data.room,0,0);
} },3000);
} },1000);
}
setTimeout(function() { gids[data.user] = gid[data.user]; }, 5000);
} else if(type == "chatroom") {
roomusers();
if(gid[data.user] != undefined) {
newmsg('' + gid[data.user][0] + ' liittyi',data.room,0,0);
} else {
setTimeout(function() { roomusers();
if(gid[data.user] != undefined) {
newmsg('' + gid[data.user][0] + ' liittyi',data.room,0,0);
} else {
setTimeout(function() {
roomusers();
if(gid[data.user] != undefined) {
newmsg('' + gid[data.user][0] + ' liittyi',data.room,0,0);
} },3000);
} },1000);
}
setTimeout(function() { gids[data.user] = gid[data.user]; }, 5000);
} else {
if(said != 0)
newmsg('Seurasi palasi takaisin.',data.room,0,1);
dcount = dcount-1;
}
}
});
socket.on('error', function(){
socket.socket.reconnect();
});
var conntimer = undefined;
socket.on('reconnecting', function (data) {
conntimer = setTimeout(function() {
if(lcon == 0) {
newmsg('Yhteys katkesi. Yritetään yhdistää uudelleen',roomid[0],0,1,0,0,1);
lcon = 1;
}
},1000);
});
socket.on('reconnect', function (data) {
clearTimeout(conntimer);
if(type == "group" || type == "chatroom")
socket.emit('part', { room: roomid[0], user: userid[0] }, function(err) { if(err) console.error(err); });
$.each(roomid, function( index, value ) {
if(value != undefined) {
socket.emit('join', { room: value, user: userid[index] }, function(err) { if(err) console.error(err); });
}
});
if(lcon == 1) {
newmsg('Yhteys palasi takaisin.',roomid[0],0,1,0,0,1);;
lcon = 0
}
});
socket.on('close', function (data) {
disconnect(1);
});
function disconnect(stranger) {
msgcounter = 0;
othermsgcounter = 0;
if(chatblacktimer != undefined)
clearTimeout(chatblacktimer);
lastmsg = "";
latestmsg = "";
ignoredusers = [];
gids = [];
if(disconnected != 1) {
//ga('send', 'event', 'Chat', 'Disconnect', type);
_gaq.push(['_trackEvent', 'Chat', 'Disconnect', type]);
socket.emit('part', { room: roomid[0], user: userid[0]}, function(err) { if(err) console.error(err); });
if(type == "group") {
socket.emit('part', { room: roomid[0], user: roomid[0]}, function(err) { if(err) console.error(err); });
$.each(roomid, function(k, v) {
socket.emit('part', { room: roomid[0], user: roomid[0]}, function(err) { if(err) console.error(err); });
});
socket.emit('part', { room: roomid[0], user: roomid[0]}, function(err) { if(err) console.error(err); });
}
location.hash = "disconnected";
clearTimeout(myVar);
if(keepactive != 1) {
$.post("//panettaa.org/handler.php", {
leave : type,
uid : userid[0]
}); }
if(webrtc != undefined)
webrtc.leaveRoom();
if(webrtc != undefined && type != "video")
closewebcam(1);
$('.searching').remove();
$('.chat[data-id="0"] .medias').popover("hide");
$('.chat[data-id="0"] .picupload').popover("hide");
$('.chat[data-id="0"] .videoupload').popover("hide");
$('.chat[data-id="0"] .drawbtn').popover("hide");
$('.chat[data-id="0"] .audioupload').popover("hide");
$('.chat[data-id="0"] .gifupload').popover("hide");
$('.chat[data-id="0"] .smileybtn').popover("hide");
said = 0;
disconnected = 1;
$('.chatinputs[data-id="0"] textarea, .chatinputs[data-id="0"] input, .chatinputs[data-id="0"] button, #addfriends').attr('disabled', 'disabled');
$(".disconnect").removeClass("btn-danger").addClass("btn-success").html(' Uusi (ESC) ');
if(!is_vip) {
$(".disconnect").attr('disabled', 'disabled');
setTimeout(function() { $(".disconnect").attr('disabled', false); },2000);
}
if(stranger == 1)
newmsg("Seurasi lähti.",roomid[0],0,1);
else if(stranger == 0)
newmsg("Lopetit keskustelun seurasi kanssa.",roomid[0],0,1);
if(type == "video") {
$(".pausewebcam, .pausewebcam2").hide();
pausewebcam(1);
if(stranger == 1)
$("#remoteVideo").html('Seurasi lähti. ');
else if(stranger == 0)
$("#remoteVideo").html('Lopetit keskustelun seurasi kanssa. ');
}
if(type == "match")
$(".gonline").hide();
if(mobilesize == 0)
newmsg('',roomid[0],0,1);
else if(type != "video")
newmsg('',roomid[0],0,1);
if(roomid[0] == undefined || chaton == 0)
newmsg(endbuttons(1),roomid[0],0,1);
else
newmsg(endbuttons(0),roomid[0],0,1);
chaton = 0;
window.clearInterval(updating);
if(stranger == 1)
flashTitle("Seurasi lähti");
$( ".menuitem, .navbar a" ).attr( "target", "_self" );
}
}
$(window).bind('beforeunload', function() {
if(chaton) {
return 'Haluatko varmasti lähteä? Keskustelu katkeaa.';
} else {
socket.emit('part', { room: roomid[0], user: userid[0]}, function(err) { if(err) console.error(err); });
var fd = new FormData();
fd.append('leave', type);
fd.append('uid', userid[0]);
navigator.sendBeacon("//panettaa.org/handler.php",fd);
}
});
window.addEventListener("unload", function logData() {
if(chaton) {
if(chatis && keepactive != 1) {
socket.emit('part', { room: roomid[0], user: userid[0]}, function(err) { if(err) console.error(err); });
var fd = new FormData();
fd.append('leave', type);
fd.append('uid', userid[0]);
navigator.sendBeacon("//panettaa.org/handler.php",fd);
}
userid[0] = "";
}
});
function changenick(lol) {
if(lol == 1)
var text = "Tunnus varattu! ";
else
var text = "";
bootbox.prompt(text + "Valitse uusi käyttäjätunnus", function(result) {
if (result === null) {
} else {
localStorage.username = result;
$.post("//www.omegle.fi/handler.php", {
changenick : type,
uid : localStorage.username,
rid : location.pathname.substring(location.pathname.lastIndexOf("/") + 1).slice(0,-5),
ouid : userid[0]
}).done(function (data) {
if(data == "true") {
roomusers();
} else {
changenick(1);
}
});
}
});
}
setTimeout(function() {
if($( window ).width() > 768) {
$("#smileys").html($("#smileylist").text());
}
},1000);