msg_send_start=false; latest_msg=null; create_dialog_count=0; function create_dialog(title,content=null,onClose=null,markdown=true){ let rand = Math.floor(Math.random() * 5000); create_dialog_count++; if(content==null){ content=title; title=''; } $('body').append("
"+title+"X
"+content+"
"); $('#dialog_'+rand).hide(); if(markdown==true) $('#dialog_'+rand+'_content').html(marked.parse(content)); $('#dialog_'+rand).show('fade'); return 'dialog_'+rand; } function create_confirm(title,content,onYes=null,onNo=null){ let rand = Math.floor(Math.random() * 5000); let yesButton=''; if(onYes!==null) yesButton+=onYes; yesButton+=";$('#confirm_"+rand+"').hide('fade');"; let noButton=''; if(onNo!==null) noButton+=onNo; noButton+=";$('#confirm_"+rand+"').hide('fade');"; $('body').append("
"+title+"
"+content+"

"); $('#confirm_'+rand).hide(); $('#confirm_'+rand).show('fade'); return 'confirm_'+rand; } function alert(title=null,content=null,onClose=null){ if(content===null){ content=title; title=''; } create_dialog(title,content,onClose); } deletemsg_start=false; function open_msg_options(msg_id){ $('#msg_options').html(""+`
Are you sure to delete this message?

`); if(typeof $('#'+msg_id+'_fromUser')[0]==='object'){ $('#msg_options').append(`

`); } $('#msg_options').dialog('open'); } function delete_msg_ok(msg_id,callback=null){ if(deletemsg_start===true){ console.log('deleting ongoing, cancelated'); return; } deletemsg_start=true; $.get('./send.php?a&delete='+msg_id).done(function(data){ console.log(msg_id); if(data==1){ $('#'+msg_id).remove(); deletemsg_start=false; if(callback!==null){ callback(); } } }).always(function(){ deletemsg_start=false; }); } function replace_url(url_to_replace){ history.replaceState({}, 'Title', url_to_replace); } function add_message_server(response,msg_id,model=null){ if(model!==null){ model=""+model.replace(/\([^)]*\)/g, '')+"
"; } else{ model=""; } $('#messages').append("
"+marked.parse(response,{breaks:true})+model+"
"+response+"
"); latest_msg="msg_"+msg_id; $('#char_creator').html(bot_owner_name); setTimeout(function(){ document.getElementById(latest_msg).scrollIntoView(); },200); } function add_message_user(response,msg_id){ $('#messages').append("
"+marked.parse(response,{breaks:true})+"
"+response+"
"); latest_msg="msg_"+msg_id; $('#char_creator').html(chat_char_name+' is typing...'); setTimeout(function(){ document.getElementById(latest_msg).scrollIntoView(); },200); } function removeLinks(text) { const urlPattern = /https?:\/\/[^\s]+/g; return text.replace(urlPattern, ''); } function containsLinks(text) { const urlPattern = /https?:\/\/[^\s]+/g; return urlPattern.test(text); } function extractLinks(text) { const urlPattern = /https?:\/\/[^\s]+/g; const matches = text.match(urlPattern); return matches ? matches : []; } function removeMarkdownImages(text) { const markdownImagePattern = /!\[.*?\]\((https?:\/\/[^\s]+)\)/g; return text.replace(markdownImagePattern, ''); } function extractImageLinks(markdown) { const imagePattern = /!\[.*?\]\((.*?)\)/g; let matches; const links = []; while ((matches = imagePattern.exec(markdown)) !== null) { links.push(matches[1]); } return links; } tmp_vision=null; function send_msg(botId,text=null,vision_url=null){ let send_msg = $('#msg_to_char')[0].value.trim(); if(text!==null) send_msg = text.trim(); let vision_include=''; if(containsLinks(send_msg)){ vision_url=extractImageLinks(send_msg)[0]; send_msg=removeMarkdownImages(send_msg).replace().trim(); vision_include="\n\n![]("+vision_url+")"; } if(vision_url!=null){ vision_include="\n\n![]("+vision_url+")"; } if(msg_send_start===false && send_msg.length>0){ msg_send_start=true; $('#photo_included').hide(); $('#photo_included').html(''); $('#msg_to_char')[0].value=""; add_message_user(send_msg+vision_include); $.post('./send.php?a',{bot_id: botId,msg:send_msg, vision:vision_url}).done(function(data){ //console.log(data); if(is_json(data)){ let json_msg = JSON.parse(data); //console.log(latest_msg); if(typeof json_msg['alert']==='string'){ alert(json_msg['alert']); } $('#'+latest_msg).attr('id','msg_'+json_msg['msg_user_id']); $('#'+latest_msg+'_fromUser').attr('id','msg_'+json_msg['msg_user_id']+'_fromUser'); $('#'+latest_msg+'_org').attr('id','msg_'+json_msg['msg_user_id']+'_org'); add_message_server(json_msg['response'],json_msg['msg_assistant_id'],json_msg['model']); if(typeof json_msg['voice']==='string'){ let voice=new Audio('./chat_voice.php?'+json_msg['voice']); voice.loop=false; voice.play(); } } else{ errorEmote_show(); $('#'+latest_msg).remove(); create_dialog('',data); $('#char_creator').html(bot_owner_name); $('#msg_to_char')[0].value=send_msg+vision_include; } }).always(function(){ msg_send_start=false; tmp_vision=null; }); } } bg_char_toggled=false; function bg_character_toggle(){ if(bg_char_toggled===false){ $('#messages').css('opacity','0'); bg_char_toggled=true; } else{ $('#messages').css('opacity','1'); bg_char_toggled=false; } } $(document).ready(function(){ $(document).on('click',function(){ if(bg_char_toggled===true){ bg_character_toggle(); } }); }); function character_counter(box_id,chars,max){ $('#'+box_id).html(chars.length+"/"+max); } function is_json(str) { if(isNaN(str)===false){ return false; } try { JSON.parse(str); } catch (e) { return false; } return true; } function loader_show(){ $('#loader').css('background-color','transparent'); $('#loader').show('fade'); $('#loader_circle').show('fade'); } function loader_hide(){ $('#loader_logo').hide(); $('#loader').hide('fade'); } go_to_protect=false; ac_page=null; function go_to(page,data_post=null,protect=null){ ac_page=page; if(go_to_protect!==false){ if(data_post!==null){ let texto = '{'; let tmp_count=0; for (const chave in data_post) { if(tmp_count>0) texto+=","; texto += chave+":'"+data_post[chave]+"'"; tmp_count++; } texto += '}'; data_post=texto; } create_confirm(`Leaving the page`,`It looks like you are doing important things on this page. Are you sure you want to quit?`,"go_to_protect=false;go_to('"+page+"',"+data_post+","+protect+");"); return; } loader_show(); eyebrowRise_hide(); errorEmote_hide(); if(page.includes('.php')){ $( "#main_content" ).load( "./screens/"+page , data_post, function( response, status, xhr ) { if ( status == "error" ) { alert(status); } else{ page=page.replace('?','&'); history.replaceState({}, 'Title', './?page='+page.replace(".php", "")); loader_hide(); if(protect!==null) go_to_protect=true; } }); } else{ $( "#main_content").load( "./screens/"+page+".php", data_post, function( response, status, xhr ) { if ( status == "error" ) { alert(status); } else{ history.replaceState({}, 'Title', './?page='+page); loader_hide(); set_ac_page(page); if(protect!==null) go_to_protect=true; } }); } } function set_ac_page(page_id){ $('.bottom_menu_bar .bottom_menu_bar_item_selected').attr('class','bottom_menu_bar_item'); $('#page_'+page_id).attr('class','bottom_menu_bar_item_selected'); } eyebrow_timeout=null; function eyebrowRise_show(){ $('#eyebrow_raise').show(function(){ $('#eyebrow_raise').css('left','-1.4rem'); $('#eyebrow_raise').css('top','30vh'); $('#eyebrow_raise').css('width','5rem'); $('#eyebrow_raise').css('transform','rotate(30deg)'); }); } function eyebrowRise_hide(){ $('#eyebrow_raise').css('left','-10rem'); $('#eyebrow_raise').css('top','30vh'); $('#eyebrow_raise').css('width','5rem'); $('#eyebrow_raise').css('transform','rotate(rotate(333deg))'); } function errorEmote_show(){ $('#error_emote').show(function(){ $('#error_emote').css('right','-2rem'); $('#error_emote').css('top','-2rem'); $('#error_emote').css('width','10rem'); $('#error_emote').css('transform','rotate(329deg)'); }); } function errorEmote_hide(){ $('#error_emote').css('right','-10rem'); $('#error_emote').css('top','-10rem'); $('#error_emote').css('width','5rem'); $('#error_emote').css('transform','rotate(329deg)'); } function floating_text(text='❤',x_pos=0,y_pos=0){ let random_id=Math.floor(Math.random() * 100000); $('#heart_main').append(`
`+text+`
`); let random_x=(window.innerWidth / 2) + x_pos + (Math.floor(Math.random() * 50) - Math.floor(Math.random() * 150)); let random_y=(window.innerHeight / 2) + y_pos + (Math.floor(Math.random() * 80) - Math.floor(Math.random() * 120)); setTimeout(function(){ $('#heart_'+random_id).css({top: random_y, left: random_x, fontSize:'3.5rem'}); setTimeout(function(){ let random_size=Math.floor(Math.random() * 50); let random_rotate=Math.floor(Math.random() * 65) - Math.floor(Math.random() * 65); let random_x2=random_x + (Math.floor(Math.random() * 50) - Math.floor(Math.random() * 150)); $('#heart_'+random_id).css({top: '-500', left: random_x2, fontSize: parseInt(Math.floor(Math.random() * (16 - 12 + 1)) + 12)+'rem',transitionDuration:'4s', transform:'rotate('+random_rotate+'deg)'}); setTimeout(function(){ $('#heart_'+random_id).remove(); },5000); },600); },100); //console.log(random_id); } function animOk_show(){ $('#anim_ok').show(function(){ $('#anim_ok').css('right','25vw'); $('#anim_ok').css('left','25vw'); $('#anim_ok').css('top','30vh'); $('#anim_ok').css('width','50vw'); setTimeout(function(){ animOk_hide(); }, 2000); }); } function animOk_hide(){ $('#anim_ok').hide('fade', function(){ $('#anim_ok').css('right','50vw'); $('#anim_ok').css('left','50vw'); $('#anim_ok').css('top','50vh'); $('#anim_ok').css('width','0vw'); }); } function translate(hashID){ var sourceText = $('#'+hashID).html(); var sourceLang = 'en'; console.log(sourceText); var targetLang = ''; var url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl="+ sourceLang + "&tl=" + targetLang + "&dt=t&q=" + encodeURI(sourceText); $.getJSON(url, function(data) { gettedTXT = data; let tmp_out = data[0]; let n_tmp_out=''; let count=0; tmp_out.forEach(function(a){ n_tmp_out=n_tmp_out + a[0]; if(count>0){ n_tmp_out=n_tmp_out + "\r\n"; }; count++; }); $('#'+hashID).html(n_tmp_out); }); } function to_clipboard(text){ navigator.clipboard.writeText(text); } last_url=null; function update_last_url(){ last_url=window.location.href; $.get('./?last_url='+encodeURIComponent(last_url)); } function bg_data_receive(){ if(typeof $('#bg_data_load')[0]==='undefined'){ $('body').append(``); } let data_container=$('#bg_data_load'); $('#bg_data_load').load('/screens/bg_data_load.php',function(){ setTimeout(function(){ bg_data_receive(); },2000); }); } function clubmate_buy_post(post_id){ $.get('/screens/clubmate.php?buy='+post_id).done(function(data){ if(is_json(data)===true){ let json_data=JSON.parse(data); $('#post_'+post_id+'_clubmate_frame').hide(); $('#post_'+post_id+'_clubmate_image').attr('src',json_data.url); } else{ alert(data); } }); } function shake_notifications(){ $('#notifications_icon').addClass('shake-animation'); setTimeout(function() { $('#notifications_icon').removeClass('shake-animation'); }, 1000); } p_shake=false; p_shake_interval=false; function persistent_shake_notifications(){ shake_notifications(); p_shake=true; p_shake_interval=setInterval(function(){ if(p_shake==true){ shake_notifications(); } else{ clearInterval(p_shake_interval); } },3000); } update_activity_running=false; if(typeof update_user_activity!=='undefined') clearInterval(update_user_activity); update_user_activity=setInterval(function(){ if(update_activity_running===true) return; update_activity_running=true; $.get('./?update_activity').done(function(data){ if(data!=''){ $('body').append(''); } }).always(function(){ update_activity_running=false; }); },5000); function open_external(url){ window.open(url) }function comments_context_menu(comment_id){ function detect_type(from) { if (from.startsWith('user_')) { return 'user'; } else if (from.startsWith('bot_')) { return 'bot'; } return null; // Retorna null se não for nenhum dos dois } // Função para extrair o ID da string function extract_id(from) { // Usa uma expressão regular para capturar o ID const match = from.match(/(?:user_|bot_)(\d+)/); return match ? match[1] : null; // Retorna o ID ou null se não encontrar } let comment_text=$('#comment_'+comment_id+'_text').html(); let comment_from=$('#comment_'+comment_id+'_text').attr('from'); console.log(comment_text); console.log(comment_id); console.log(comment_from); let type_from = detect_type(comment_from); let type_id = extract_id(comment_from); let is_owner=false; let text=`

`; if (type_from === 'user') { if(is_owner===true){ text+=`

`; } } alert(`Options`,text); } function post_delete_comment(CommentID=null,close=false){ if(CommentID===null) return; $.get('./screens/post_comments.php?delete_comment='+CommentID).done(function(data){ if(data=='1'){ $('#post_comment_'+CommentID+'_box').remove(); if(close==true){ $('.dialog_title close')[$('.dialog_title close').length-1].click(); } } }); } var playing_audio = false; function play_audio(file) { if (playing_audio) return; else playing_audio=true; let main = "/audio/"; let language = ""; function tryPlay(lang) { let filePath = main + lang + '/' + file + '.mp3'; fetch(filePath, { method: 'HEAD' }) .then(response => { if (response.ok) { let audio = new Audio(filePath); playing_audio = true; audio.play().catch(err => { playing_audio = false; }); audio.onended = () => { playing_audio = false; }; } }) .catch(); } tryPlay(language); }