diff --git a/public/script.js b/public/script.js index 196bf2b63..6c50ec663 100644 --- a/public/script.js +++ b/public/script.js @@ -363,7 +363,7 @@ function newMesPattern(name) { ////////////////////////////////////////// function checkOnlineStatus() { - ///////// REMOVED LINES THAT DUPLICATE RA_CHeckOnlineStatus FEATURES + ///////// REMOVED LINES THAT DUPLICATE RA_CHeckOnlineStatus FEATURES if (online_status == "no_connection") { $("#online_status_indicator2").css("background-color", "red"); //Kobold @@ -463,7 +463,7 @@ async function getStatus() { online_status = "no_connection"; } } -} +} function resultCheckStatus() { is_api_button_press = false; @@ -822,31 +822,31 @@ function addOneMessage(mes, type = "normal") { var HTMLForEachMes = '
' + - '
' + - '' + - '
' + - '' + - '
' + - '
' + - '' + - '
' + - '
' + - '
' + - characterName + - '
' + - '
'+ - ''+ - '
' + - '
'+ - ''+ - '
' + - '
' + - '
' + - '
' + - '
' + bias + '
' + - '
' + - ' ' + - '
' + + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + characterName + + '
' + + '
' + + '' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + bias + '
' + + '
' + + ' ' + + '
' + '
'; if (type !== 'swipe') { @@ -865,13 +865,13 @@ function addOneMessage(mes, type = "normal") { newMessage.find('.avatar img').on('error', function () { $(this).attr("src", "/img/user-slash-solid.svg"); $(this).css('filter', 'invert(1)'); - }); + }); if (type === 'swipe') { $("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.mes_block').children('.mes_text').html(''); $("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.mes_block').children('.mes_text').append(messageText); } else { $("#chat").children().filter('[mesid="' + count_view_mes + '"]').children('.mes_block').children('.mes_text').append(messageText); - hideSwipeButtons(); + hideSwipeButtons(); count_view_mes++; } var $textchat = $("#chat"); @@ -971,9 +971,9 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length //$('#chat').children().last().css({'transition':'all 0.5s ease-in-out'}); //$('#chat').children().last().css({'transform':'translateX(100vh) scale(0.1,0.1)'}); //$('#chat').children().last().css({'opacity':'0'}); - setTimeout(function(){ + setTimeout(function () { $('#chat').children().last().remove(); - },1000); + }, 1000); } } @@ -1039,7 +1039,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length console.log('Generate calls addOneMessage'); addOneMessage(chat[chat.length - 1]); } -//////////////////////////////////// + //////////////////////////////////// var chatString = ''; var arrMes = []; var mesSend = []; @@ -1066,10 +1066,10 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length } function appendToStoryString(value, prefix) { - if (value !== undefined && value.length > 0) { - return prefix + value + '\n'; - } - return ''; + if (value !== undefined && value.length > 0) { + return prefix + value + '\n'; + } + return ''; } if (is_pygmalion) { @@ -1077,31 +1077,31 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length storyString += appendToStoryString(charPersonality, 'Personality: '); storyString += appendToStoryString(Scenario, 'Scenario: '); } else { - if (charDescription !== undefined) { - if (charPersonality.length > 0) { - charPersonality = name2 + "'s personality: " + charPersonality; + if (charDescription !== undefined) { + if (charPersonality.length > 0) { + charPersonality = name2 + "'s personality: " + charPersonality; + } + } + + storyString += appendToStoryString(charDescription, ''); + + if (storyString.endsWith('\n')) { + storyString = storyString.slice(0, -1); + } + + if (count_view_mes < topAnchorDepth) { + storyString += '\n' + appendToStoryString(charPersonality, ''); } } - - storyString += appendToStoryString(charDescription, ''); - - if (storyString.endsWith('\n')) { - storyString = storyString.slice(0, -1); - } - - if (count_view_mes < topAnchorDepth) { - storyString += '\n' + appendToStoryString(charPersonality, ''); - } - } -////////////////////////////////// + ////////////////////////////////// var count_exm_add = 0; console.log('emptying chat2'); var chat2 = []; var j = 0; - console.log('pre-replace chat.length = '+chat.length); + console.log('pre-replace chat.length = ' + chat.length); for (var i = chat.length - 1; i >= 0; i--) { - + if (j == 0) { chat[j]['mes'] = chat[j]['mes'].replace(/{{user}}/gi, name1); chat[j]['mes'] = chat[j]['mes'].replace(/{{char}}/gi, name2); @@ -1123,13 +1123,13 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length if (chat[j]['is_system']) { chat2[i] = ''; } - + // replace bias markup - chat2[i] = (chat2[i] ?? '').replace(/{([^}]+)}/g, ''); + chat2[i] = (chat2[i] ?? '').replace(/{([^}]+)}/g, ''); //console.log('replacing chat2 {}s'); j++; } - console.log('post replace chat.length = '+chat.length); + console.log('post replace chat.length = ' + chat.length); //chat2 = chat2.reverse(); var this_max_context = 1487; if (main_api == 'kobold') this_max_context = max_context; @@ -1158,23 +1158,23 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length extension_prompt += '\n'; } /////////////////////// swipecode - if(type == 'swipe'){ - + if (type == 'swipe') { + console.log('pre swipe shift: ' + chat2.length); console.log('shifting swipe chat2'); chat2.shift(); - + } - console.log('post swipe shift:'+chat2.length); + console.log('post swipe shift:' + chat2.length); var i = 0; for (var item of chat2) {//console.log(encode("dsfs").length); chatString = item + chatString; if (encode(JSON.stringify( - worldInfoString + storyString + chatString + - anchorTop + anchorBottom + - charPersonality + promptBias + extension_prompt - )).length + 120 < this_max_context) { //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide) + worldInfoString + storyString + chatString + + anchorTop + anchorBottom + + charPersonality + promptBias + extension_prompt + )).length + 120 < this_max_context) { //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide) //if (is_pygmalion && i == chat2.length-1) item='\n'+item; arrMes[arrMes.length] = item; } else { @@ -1183,10 +1183,10 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length } await delay(1); //For disable slow down (encode gpt-2 need fix) - // console.log(i+' '+chat.length); - + // console.log(i+' '+chat.length); + count_exm_add = 0; - + if (i === chat.length - 1) { let mesExmString = ''; for (let iii = mesExamplesArray.length - 1; iii >= 0; iii--) { @@ -1213,7 +1213,8 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length return; function runGenerate(cycleGenerationPromt = '') { - console.log('rungenerate entered'); + + is_send_press = true; generatedPromtCache += cycleGenerationPromt; if (generatedPromtCache.length == 0) { @@ -1325,7 +1326,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length } finalPromt = worldInfoBefore + storyString + worldInfoAfter + extension_prompt + mesExmString + mesSendString + generatedPromtCache + promptBias; finalPromt = finalPromt.replace(/\r/gm, ''); - console.log('final prompt decided'); + //console.log('final prompt decided'); //if we aren't using the kobold GUI settings... if (main_api == 'textgenerationwebui' || main_api == 'kobold' && preset_settings != 'gui') { @@ -1456,7 +1457,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length dataType: "json", contentType: "application/json", success: function (data) { - console.log('generation success'); + //console.log('generation success'); tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter.. @@ -1496,7 +1497,8 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length message_already_generated.indexOf('<|endoftext|>') === -1 && //if there is no stamp in the response msg tokens_already_generated < parseInt(amount_gen) && //if the gen'd msg is less than the max response length.. getMessage.length > 0) { //if we actually have gen'd text at all... - runGenerate(getMessage); //generate again with the 'GetMessage' argument.. + runGenerate(getMessage); + console.log('returning to make pyg generate again'); //generate again with the 'GetMessage' argument.. return; } @@ -1546,21 +1548,21 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length if (type === 'force_name2') this_mes_is_name = true; //getMessage = getMessage.replace(/^\s+/g, ''); if (getMessage.length > 0) { - if(chat[chat.length-1]['swipe_id'] === undefined || - chat[chat.length-1]['is_user']){type = 'normal';} - if(type === 'swipe'){ - - chat[chat.length-1]['swipes'][chat[chat.length-1]['swipes'].length] = getMessage; - if(chat[chat.length-1]['swipe_id'] === chat[chat.length-1]['swipes'].length-1){ + if (chat[chat.length - 1]['swipe_id'] === undefined || + chat[chat.length - 1]['is_user']) { type = 'normal'; } + if (type === 'swipe') { + + chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage; + if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) { //console.log(getMessage); - chat[chat.length-1]['mes'] = getMessage; + chat[chat.length - 1]['mes'] = getMessage; console.log('runGenerate calls addOneMessage for swipe'); - addOneMessage(chat[chat.length-1], 'swipe'); - }else{ - chat[chat.length-1]['mes'] = getMessage; + addOneMessage(chat[chat.length - 1], 'swipe'); + } else { + chat[chat.length - 1]['mes'] = getMessage; } is_send_press = false; - }else{ + } else { console.log('entering chat update routine for non-swipe post'); is_send_press = false; chat[chat.length] = {}; @@ -1582,7 +1584,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length } console.log('runGenerate calls addOneMessage'); addOneMessage(chat[chat.length - 1]); - console.log('should hide loading mes and return with send button now'); + $("#send_but").css("display", "inline"); $("#loading_mes").css("display", "none"); @@ -1593,13 +1595,13 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length saveChat(); } */ } - + } else { Generate('force_name2'); } } else { - console.log('final re-setting of send button due to error'); + $("#send_but").css("display", "inline"); $("#loading_mes").css("display", "none"); showSwipeButtons(); @@ -1610,7 +1612,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length //console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)'); $("#send_but").css("display", "inline"); - console.log('attempting to show swipes'); + showSwipeButtons(); $("#loading_mes").css("display", "none"); @@ -1618,15 +1620,16 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length }, error: function (jqXHR, exception) { + $("#send_textarea").removeAttr('disabled'); is_send_press = false; $("#send_but").css("display", "inline"); $("#loading_mes").css("display", "none"); console.log(exception); console.log(jqXHR); - + } - + }); //end of "if not data error" } //rungenerate ends @@ -1745,10 +1748,11 @@ async function getChat() { const response = await $.ajax({ type: 'POST', url: '/getchat', - data: JSON.stringify({ - ch_name: characters[this_chid].name, - file_name: characters[this_chid].chat, - avatar_url: characters[this_chid].avatar }), + data: JSON.stringify({ + ch_name: characters[this_chid].name, + file_name: characters[this_chid].chat, + avatar_url: characters[this_chid].avatar + }), dataType: 'json', contentType: 'application/json', }); @@ -1797,39 +1801,50 @@ function openNavToggle() { } } +////////// OPTIMZED MAIN API CHANGE FUNCTION //////////// + function changeMainAPI() { - if ($("#main_api").find(":selected").val() == "kobold") { - $("#kobold_api").css("display", "block"); - $("#novel_api").css("display", "none"); - $("#textgenerationwebui_api").css("display", "none"); - main_api = "kobold"; - $("#max_context_block").css("display", "block"); - $("#amount_gen_block").css("display", "block"); - $("#softprompt_block").css("display", "block"); - } - if ($("#main_api").find(":selected").val() == "textgenerationwebui") { - $("#kobold_api").css("display", "none"); - $("#novel_api").css("display", "none"); - $("#textgenerationwebui_api").css("display", "block"); - main_api = "textgenerationwebui"; - $("#max_context_block").css("display", "block"); - $("#amount_gen_block").css("display", "block"); - $("#softprompt_block").css("display", "block"); - $("#amount_gen_block").children().prop("disabled", false); - $("#amount_gen_block").css("opacity", 1.0); + const selectedVal = $("#main_api").val(); + const apiElements = { + "kobold": { + apiElem: $("#kobold_api"), + maxContextElem: $("#max_context_block"), + amountGenElem: $("#amount_gen_block"), + softPromptElem: $("#softprompt_block") + }, + "textgenerationwebui": { + apiElem: $("#textgenerationwebui_api"), + maxContextElem: $("#max_context_block"), + amountGenElem: $("#amount_gen_block"), + softPromptElem: $("#softprompt_block") + }, + "novel": { + apiElem: $("#novel_api"), + maxContextElem: $("#max_context_block"), + amountGenElem: $("#amount_gen_block"), + softPromptElem: $("#softprompt_block") + } + }; + + for (const apiName in apiElements) { + const apiObj = apiElements[apiName]; + const isCurrentApi = selectedVal === apiName; + apiObj.apiElem.css("display", isCurrentApi ? "block" : "none"); + apiObj.maxContextElem.css("display", isCurrentApi && apiName !== "novel" ? "block" : "none"); + apiObj.amountGenElem.css("display", isCurrentApi && apiName !== "novel" ? "block" : "none"); + apiObj.softPromptElem.css("display", isCurrentApi && apiName !== "novel" ? "block" : "none"); + + if (isCurrentApi && apiName === "textgenerationwebui") { + apiObj.amountGenElem.children().prop("disabled", false); + apiObj.amountGenElem.css("opacity", 1.0); + } } - if ($("#main_api").find(":selected").val() == "novel") { - $("#kobold_api").css("display", "none"); - $("#novel_api").css("display", "block"); - $("#textgenerationwebui_api").css("display", "none"); - main_api = "novel"; - $("#max_context_block").css("display", "none"); - $("#amount_gen_block").css("display", "none"); - $("#softprompt_block").css("display", "none"); - } + main_api = selectedVal; } +//////////////////////////////////////////////////// + async function getUserAvatars() { $("#user_avatar_block").html(""); //RossAscends: necessary to avoid doubling avatars each QuickRefresh. $("#user_avatar_block").append('
+
'); @@ -2723,222 +2738,222 @@ $(document).ready(function () { ///// SWIPE BUTTON CLICKS /////// - $(document).on('click', '.swipe_right', function(){ //when we click swipe right button + $(document).on('click', '.swipe_right', function () { //when we click swipe right button const swipe_duration = 120; const swipe_range = 700; //console.log(swipe_range); let run_generate = false; let run_swipe_right = false; - if(chat[chat.length-1]['swipe_id'] === undefined){ // if there is no swipe-message in the last spot of the chat array - chat[chat.length-1]['swipe_id'] = 0; // set it to id 0 - chat[chat.length-1]['swipes'] = []; // empty the array - chat[chat.length-1]['swipes'][0] = chat[chat.length-1]['mes']; //assign swipe array with last message from chat + if (chat[chat.length - 1]['swipe_id'] === undefined) { // if there is no swipe-message in the last spot of the chat array + chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0 + chat[chat.length - 1]['swipes'] = []; // empty the array + chat[chat.length - 1]['swipes'][0] = chat[chat.length - 1]['mes']; //assign swipe array with last message from chat } - chat[chat.length-1]['swipe_id']++; //make new slot in array + chat[chat.length - 1]['swipe_id']++; //make new slot in array //console.log(chat[chat.length-1]['swipes']); - if(parseInt(chat[chat.length-1]['swipe_id']) === chat[chat.length-1]['swipes'].length){ //if swipe id of last message is the same as the length of the 'swipes' array - run_generate = true; - }else if(parseInt(chat[chat.length-1]['swipe_id']) < chat[chat.length-1]['swipes'].length){ //otherwise, if the id is less than the number of swipes - chat[chat.length-1]['mes'] = chat[chat.length-1]['swipes'][chat[chat.length-1]['swipe_id']]; //load the last mes box with the latest generation + if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { //if swipe id of last message is the same as the length of the 'swipes' array + run_generate = true; + } else if (parseInt(chat[chat.length - 1]['swipe_id']) < chat[chat.length - 1]['swipes'].length) { //otherwise, if the id is less than the number of swipes + chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; //load the last mes box with the latest generation run_swipe_right = true; //then swipe } - - if(chat[chat.length-1]['swipe_id'] > chat[chat.length-1]['swipes'].length){ //if we swipe right while generating (the swipe ID is greater than what we are viewing now) - chat[chat.length-1]['swipe_id'] = chat[chat.length-1]['swipes'].length; //show that message slot (will be '...' while generating) + + if (chat[chat.length - 1]['swipe_id'] > chat[chat.length - 1]['swipes'].length) { //if we swipe right while generating (the swipe ID is greater than what we are viewing now) + chat[chat.length - 1]['swipe_id'] = chat[chat.length - 1]['swipes'].length; //show that message slot (will be '...' while generating) } - if(run_generate){ //hide swipe arrows while generating + if (run_generate) { //hide swipe arrows while generating $(this).css('display', 'none'); - + } - if(run_generate || run_swipe_right){ // handles animated transitions when swipe right, specifically height transitions between messages - + if (run_generate || run_swipe_right) { // handles animated transitions when swipe right, specifically height transitions between messages + let this_mes_div = $(this).parent(); let this_mes_block = $(this).parent().children('.mes_block').children('.mes_text'); const this_mes_div_height = this_mes_div[0].scrollHeight; const this_mes_block_height = this_mes_block[0].scrollHeight; - + this_mes_div.children('.swipe_left').css('display', 'flex'); this_mes_div.children('.mes_block').transition({ // this moves the div back and forth - x: '-'+swipe_range, - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - - const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10); - //console.log(parseInt(chat[chat.length-1]['swipe_id'])); - //console.log(chat[chat.length-1]['swipes'].length); - if(run_generate && parseInt(chat[chat.length-1]['swipe_id']) === chat[chat.length-1]['swipes'].length){ - //console.log('showing ...'); - $("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.mes_block').children('.mes_text').html('...'); //shows ... while generating - }else{ - //console.log('showing previously generated swipe candidate, or "..."'); - addOneMessage(chat[chat.length-1], 'swipe'); + x: '-' + swipe_range, + duration: swipe_duration, + easing: animation_rm_easing, + queue: false, + complete: function () { + + const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10); + //console.log(parseInt(chat[chat.length-1]['swipe_id'])); + //console.log(chat[chat.length-1]['swipes'].length); + if (run_generate && parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { + //console.log('showing ...'); + $("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.mes_block').children('.mes_text').html('...'); //shows ... while generating + } else { + //console.log('showing previously generated swipe candidate, or "..."'); + addOneMessage(chat[chat.length - 1], 'swipe'); + } + let new_height = this_mes_div_height - (this_mes_block_height - this_mes_block[0].scrollHeight); + if (new_height < 103) new_height = 103; + + + this_mes_div.animate({ height: new_height + 'px' }, { + duration: 100, + queue: false, + progress: function () { + // Scroll the chat down as the message expands + if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); + }, + complete: function () { + this_mes_div.css('height', 'auto'); + // Scroll the chat down to the bottom once the animation is complete + if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); } - let new_height = this_mes_div_height-(this_mes_block_height - this_mes_block[0].scrollHeight); - if(new_height < 103) new_height = 103; - - - this_mes_div.animate({height: new_height+'px'}, { - duration: 100, - queue:false, - progress: function() { - // Scroll the chat down as the message expands - if(is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); - }, - complete: function() { - this_mes_div.css('height', 'auto'); - // Scroll the chat down to the bottom once the animation is complete - if(is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); - } - }); - this_mes_div.children('.mes_block').transition({ - x: swipe_range, - duration: 0, + }); + this_mes_div.children('.mes_block').transition({ + x: swipe_range, + duration: 0, + easing: animation_rm_easing, + queue: false, + complete: function () { + this_mes_div.children('.mes_block').transition({ + x: '0px', + duration: swipe_duration, easing: animation_rm_easing, - queue:false, - complete: function() { - this_mes_div.children('.mes_block').transition({ - x: '0px', - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - if(run_generate && !is_send_press && parseInt(chat[chat.length-1]['swipe_id']) === chat[chat.length-1]['swipes'].length){ - console.log('caught here 2'); - is_send_press = true; - Generate('swipe'); - }else{ - if(parseInt(chat[chat.length-1]['swipe_id']) !== chat[chat.length-1]['swipes'].length){ - console.log('caught here 3'); - saveChat(); - } - } - } - }); + queue: false, + complete: function () { + if (run_generate && !is_send_press && parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { + console.log('caught here 2'); + is_send_press = true; + Generate('swipe'); + } else { + if (parseInt(chat[chat.length - 1]['swipe_id']) !== chat[chat.length - 1]['swipes'].length) { + console.log('caught here 3'); + saveChat(); + } + } } - }); - } + }); + } + }); + } }); - + $(this).parent().children('.avatar').transition({ // moves avatar aong with swipe - x: '-'+swipe_range, - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - $(this).parent().children('.avatar').transition({ - x: swipe_range, - duration: 0, + x: '-' + swipe_range, + duration: swipe_duration, + easing: animation_rm_easing, + queue: false, + complete: function () { + $(this).parent().children('.avatar').transition({ + x: swipe_range, + duration: 0, + easing: animation_rm_easing, + queue: false, + complete: function () { + $(this).parent().children('.avatar').transition({ + x: '0px', + duration: swipe_duration, easing: animation_rm_easing, - queue:false, - complete: function() { - $(this).parent().children('.avatar').transition({ - x: '0px', - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - - } - }); + queue: false, + complete: function () { + } - }); - } + }); + } + }); + } }); } - + }); - $(document).on('click', '.swipe_left', function(){ // when we swipe left..but no generation. + $(document).on('click', '.swipe_left', function () { // when we swipe left..but no generation. const swipe_duration = 120; const swipe_range = '700px'; - chat[chat.length-1]['swipe_id']--; - if(chat[chat.length-1]['swipe_id'] >= 0){ // hide the left arrow if we are viewing the first candidate of the last message block + chat[chat.length - 1]['swipe_id']--; + if (chat[chat.length - 1]['swipe_id'] >= 0) { // hide the left arrow if we are viewing the first candidate of the last message block $(this).parent().children('swipe_right_button').css('display', 'flex'); - if(chat[chat.length-1]['swipe_id'] === 0){ + if (chat[chat.length - 1]['swipe_id'] === 0) { $(this).css('display', 'none'); } - + let this_mes_div = $(this).parent(); let this_mes_block = $(this).parent().children('.mes_block').children('.mes_text'); const this_mes_div_height = this_mes_div[0].scrollHeight; this_mes_div.css('height', this_mes_div_height); const this_mes_block_height = this_mes_block[0].scrollHeight; - - chat[chat.length-1]['mes'] = chat[chat.length-1]['swipes'][chat[chat.length-1]['swipe_id']]; - $(this).parent().children('.mes_block').transition({ - x: swipe_range, - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10); -console.log('sipwing left after tr5ansition calls addOneMessage'); - addOneMessage(chat[chat.length-1], 'swipe'); - let new_height = this_mes_div_height-(this_mes_block_height - this_mes_block[0].scrollHeight); - if(new_height < 103) new_height = 103; - this_mes_div.animate({height: new_height+'px'}, { - duration: 100, - queue:false, - progress: function() { - // Scroll the chat down as the message expands - - if(is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); - }, - complete: function() { - this_mes_div.css('height', 'auto'); - // Scroll the chat down to the bottom once the animation is complete - if(is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); - } - }); - $(this).parent().children('.mes_block').transition({ - x: '-'+swipe_range, - duration: 0, + + chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; + $(this).parent().children('.mes_block').transition({ + x: swipe_range, + duration: swipe_duration, + easing: animation_rm_easing, + queue: false, + complete: function () { + const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10); + console.log('sipwing left after tr5ansition calls addOneMessage'); + addOneMessage(chat[chat.length - 1], 'swipe'); + let new_height = this_mes_div_height - (this_mes_block_height - this_mes_block[0].scrollHeight); + if (new_height < 103) new_height = 103; + this_mes_div.animate({ height: new_height + 'px' }, { + duration: 100, + queue: false, + progress: function () { + // Scroll the chat down as the message expands + + if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); + }, + complete: function () { + this_mes_div.css('height', 'auto'); + // Scroll the chat down to the bottom once the animation is complete + if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight); + } + }); + $(this).parent().children('.mes_block').transition({ + x: '-' + swipe_range, + duration: 0, + easing: animation_rm_easing, + queue: false, + complete: function () { + $(this).parent().children('.mes_block').transition({ + x: '0px', + duration: swipe_duration, easing: animation_rm_easing, - queue:false, - complete: function() { - $(this).parent().children('.mes_block').transition({ - x: '0px', - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - saveChat(); - } - }); + queue: false, + complete: function () { + saveChat(); } - }); - } + }); + } + }); + } }); - - $(this).parent().children('.avatar').transition({ - x: swipe_range, - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - $(this).parent().children('.avatar').transition({ - x: '-'+swipe_range, - duration: 0, + + $(this).parent().children('.avatar').transition({ + x: swipe_range, + duration: swipe_duration, + easing: animation_rm_easing, + queue: false, + complete: function () { + $(this).parent().children('.avatar').transition({ + x: '-' + swipe_range, + duration: 0, + easing: animation_rm_easing, + queue: false, + complete: function () { + $(this).parent().children('.avatar').transition({ + x: '0px', + duration: swipe_duration, easing: animation_rm_easing, - queue:false, - complete: function() { - $(this).parent().children('.avatar').transition({ - x: '0px', - duration: swipe_duration, - easing: animation_rm_easing, - queue:false, - complete: function() { - - } - }); + queue: false, + complete: function () { + } - }); - } + }); + } + }); + } }); } - if(chat[chat.length-1]['swipe_id'] < 0){ - chat[chat.length-1]['swipe_id'] = 0; + if (chat[chat.length - 1]['swipe_id'] < 0) { + chat[chat.length - 1]['swipe_id'] = 0; } }); @@ -3447,17 +3462,17 @@ console.log('sipwing left after tr5ansition calls addOneMessage'); select_rm_characters(); }); -//////// OPTIMIZED ALL CHAR CREATION/EDITING TEXTAREA LISTENERS /////////////// + //////// OPTIMIZED ALL CHAR CREATION/EDITING TEXTAREA LISTENERS /////////////// $("#character_name_pole").on("change keyup paste", function () { if (menu_type == "create") { create_save_name = $("#character_name_pole").val(); } }); - - $("#description_textarea, #personality_textarea, #scenario_pole"+ - "#mes_example_textarea, #firstmessage_textarea") - .on("keyup paste cut", function () { + + $("#description_textarea, #personality_textarea, #scenario_pole" + + "#mes_example_textarea, #firstmessage_textarea") + .on("keyup paste cut", function () { if (menu_type == "create") { create_save_description = $("#description_textarea").val(); create_save_personality = $("#personality_textarea").val(); @@ -3468,7 +3483,7 @@ console.log('sipwing left after tr5ansition calls addOneMessage'); saveCharacterDebounced(); } }); - + $("#talkativeness_slider").on("input", function () { if (menu_type == "create") { create_save_talkativeness = $("#talkativeness_slider").val(); @@ -3477,7 +3492,7 @@ console.log('sipwing left after tr5ansition calls addOneMessage'); } }); -/////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////// $("#api_button").click(function () { if ($("#api_url_text").val() != "") { @@ -3565,67 +3580,67 @@ console.log('sipwing left after tr5ansition calls addOneMessage'); } }); -///////////// OPTIMIZED LISTENERS FOR LEFT SIDE OPTIONS POPUP MENU ////////////////////// + ///////////// OPTIMIZED LISTENERS FOR LEFT SIDE OPTIONS POPUP MENU ////////////////////// - $("#options_button [id]").on("click", function() { + $("#options_button [id]").on("click", function () { var id = $(this).attr("id"); - - if (id == "option_select_chat") { - if (selected_group) { - // will open a chat selection screen - openNavToggle(); - $("#rm_button_characters").trigger("click"); - return; - } - if (this_chid != undefined && !is_send_press) { - getAllCharaChats(); - $("#shadow_select_chat_popup").css("display", "block"); - $("#shadow_select_chat_popup").css("opacity", 0.0); - $("#shadow_select_chat_popup").transition({ - opacity: 1.0, - duration: animation_rm_duration, - easing: animation_rm_easing, - }); - } - } - - else if (id == "option_start_new_chat") { - if (selected_group) { - // will open a group creation screen - openNavToggle(); - $("#rm_button_group_chats").trigger("click"); - return; - } - if (this_chid != undefined && !is_send_press) { - popup_type = "new_chat"; - callPopup("

Start new chat?

"); - } - } - - else if (id == "option_regenerate") { - if (is_send_press == false) { - hideSwipeButtons(); - is_send_press = true; - Generate("regenerate"); - } - } - - else if (id == "option_delete_mes") { - hideSwipeButtons(); - if ((this_chid != undefined && !is_send_press) || (selected_group && !is_group_generating)) { - $("#dialogue_del_mes").css("display", "block"); - $("#send_form").css("display", "none"); - $(".del_checkbox").each(function () { - if ($(this).parent().attr("mesid") != 0) { - $(this).css("display", "block"); - $(this).parent().children(".for_checkbox").css("display", "none"); - } - }); - } - } - }); -////////////////////////////////////////////////////////////////////////////////////////////// + if (id == "option_select_chat") { + if (selected_group) { + // will open a chat selection screen + openNavToggle(); + $("#rm_button_characters").trigger("click"); + return; + } + if (this_chid != undefined && !is_send_press) { + getAllCharaChats(); + $("#shadow_select_chat_popup").css("display", "block"); + $("#shadow_select_chat_popup").css("opacity", 0.0); + $("#shadow_select_chat_popup").transition({ + opacity: 1.0, + duration: animation_rm_duration, + easing: animation_rm_easing, + }); + } + } + + else if (id == "option_start_new_chat") { + if (selected_group) { + // will open a group creation screen + openNavToggle(); + $("#rm_button_group_chats").trigger("click"); + return; + } + if (this_chid != undefined && !is_send_press) { + popup_type = "new_chat"; + callPopup("

Start new chat?

"); + } + } + + else if (id == "option_regenerate") { + if (is_send_press == false) { + hideSwipeButtons(); + is_send_press = true; + Generate("regenerate"); + } + } + + else if (id == "option_delete_mes") { + hideSwipeButtons(); + if ((this_chid != undefined && !is_send_press) || (selected_group && !is_group_generating)) { + $("#dialogue_del_mes").css("display", "block"); + $("#send_form").css("display", "none"); + $(".del_checkbox").each(function () { + if ($(this).parent().attr("mesid") != 0) { + $(this).css("display", "block"); + $(this).parent().children(".for_checkbox").css("display", "none"); + } + }); + } + } + }); + + ////////////////////////////////////////////////////////////////////////////////////////////// //functionality for the cancel delete messages button, reverts to normal display of input form $("#dialogue_del_mes_cancel").click(function () { @@ -3802,60 +3817,60 @@ console.log('sipwing left after tr5ansition calls addOneMessage'); }); } -////////////////// OPTIMIZED RANGE SLIDER LISTENERS//////////////// + ////////////////// OPTIMIZED RANGE SLIDER LISTENERS//////////////// const sliders = [ { - sliderId: "#temp", - counterId: "#temp_counter", - format: (val) => isInt(val) ? val + ".00" : val + sliderId: "#temp", + counterId: "#temp_counter", + format: (val) => isInt(val) ? val + ".00" : val }, { - sliderId: "#amount_gen", - counterId: "#amount_gen_counter", - format: (val) => val + sliderId: "#amount_gen", + counterId: "#amount_gen_counter", + format: (val) => val }, { - sliderId: "#max_context", - counterId: "#max_context_counter", - format: (val) => val + " Tokens" + sliderId: "#max_context", + counterId: "#max_context_counter", + format: (val) => val + " Tokens" }, { - sliderId: "#rep_pen", - counterId: "#rep_pen_counter", - format: (val) => isInt(val) ? val + ".00" : val + sliderId: "#rep_pen", + counterId: "#rep_pen_counter", + format: (val) => isInt(val) ? val + ".00" : val }, { - sliderId: "#rep_pen_size", - counterId: "#rep_pen_size_counter", - format: (val) => val + " Tokens" + sliderId: "#rep_pen_size", + counterId: "#rep_pen_size_counter", + format: (val) => val + " Tokens" }, { - sliderId: "#temp_novel", - counterId: "#temp_counter_novel", - format: (val) => isInt(val) ? val + ".00" : val + sliderId: "#temp_novel", + counterId: "#temp_counter_novel", + format: (val) => isInt(val) ? val + ".00" : val }, { - sliderId: "#rep_pen_novel", - counterId: "#rep_pen_counter_novel", - format: (val) => isInt(val) ? val + ".00" : val + sliderId: "#rep_pen_novel", + counterId: "#rep_pen_counter_novel", + format: (val) => isInt(val) ? val + ".00" : val }, { - sliderId: "#rep_pen_size_novel", - counterId: "#rep_pen_size_counter_novel", - format: (val) => val + " Tokens" + sliderId: "#rep_pen_size_novel", + counterId: "#rep_pen_size_counter_novel", + format: (val) => val + " Tokens" } - ]; - - sliders.forEach(slider => { + ]; + + sliders.forEach(slider => { $(document).on("input", slider.sliderId, function () { - const value = $(this).val(); - const formattedValue = slider.format(value); - $(slider.counterId).html(formattedValue); - console.log('saving'); - saveSettingsDebounced(); + const value = $(this).val(); + const formattedValue = slider.format(value); + $(slider.counterId).html(formattedValue); + console.log('saving'); + saveSettingsDebounced(); }); - }); + }); ////////////////////////////////////////////////////////////// diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 906acb294..e6a970123 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -1,15 +1,15 @@ import { encode } from "../scripts/gpt-2-3-tokenizer/mod.js"; import { - Generate, - this_chid, - characters, - online_status, - main_api, - api_server, - api_key_novel, - is_send_press, - + Generate, + this_chid, + characters, + online_status, + main_api, + api_server, + api_key_novel, + is_send_press, + } from "../script.js"; import { LoadLocal, SaveLocal, ClearLocal, CheckLocal, LoadLocalBool } from "./f-localStorage.js"; @@ -23,8 +23,8 @@ var AdvancedCharDefsPopup = document.getElementById("character_popup"); var ConfirmationPopup = document.getElementById("dialogue_popup"); var AutoConnectCheckbox = document.getElementById("auto-connect-checkbox"); var AutoLoadChatCheckbox = document.getElementById("auto-load-chat-checkbox"); -var SelectedNavTab = ("#"+LoadLocal('SelectedNavTab')); - +var SelectedNavTab = ("#" + LoadLocal('SelectedNavTab')); + var create_save_name; var create_save_description; var create_save_personality; @@ -36,14 +36,14 @@ var perm_tokens; const observerConfig = { childList: true, subtree: true }; -const observer = new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - if (mutation.target.id === "online_status_text2") { - RA_checkOnlineStatus(); - } else if (mutation.target.parentNode === SelectedCharacterTab) { - setTimeout(RA_CountCharTokens, 200); - } - }); +const observer = new MutationObserver(function (mutations) { + mutations.forEach(function (mutation) { + if (mutation.target.id === "online_status_text2") { + RA_checkOnlineStatus(); + } else if (mutation.target.parentNode === SelectedCharacterTab) { + setTimeout(RA_CountCharTokens, 200); + } + }); }); observer.observe(document.documentElement, observerConfig); @@ -54,19 +54,19 @@ observer.observe(document.documentElement, observerConfig); //Does not break old characters/chats, as the code just uses whatever timestamp exists in the chat. //New chats made with characters will use this new formatting. export function humanizedDateTime() { - let baseDate = new Date(Date.now()); - let humanYear = baseDate.getFullYear(); - let humanMonth = baseDate.getMonth() + 1; - let humanDate = baseDate.getDate(); - let humanHour = (baseDate.getHours() < 10 ? "0" : "") + baseDate.getHours(); - let humanMinute = - (baseDate.getMinutes() < 10 ? "0" : "") + baseDate.getMinutes(); - let humanSecond = - (baseDate.getSeconds() < 10 ? "0" : "") + baseDate.getSeconds(); - let humanMillisecond = - (baseDate.getMilliseconds() < 10 ? "0" : "") + baseDate.getMilliseconds(); - let HumanizedDateTime = - humanYear +"-" +humanMonth +"-" +humanDate +" @" +humanHour +"h " +humanMinute +"m " +humanSecond +"s " +humanMillisecond +"ms"; + let baseDate = new Date(Date.now()); + let humanYear = baseDate.getFullYear(); + let humanMonth = baseDate.getMonth() + 1; + let humanDate = baseDate.getDate(); + let humanHour = (baseDate.getHours() < 10 ? "0" : "") + baseDate.getHours(); + let humanMinute = + (baseDate.getMinutes() < 10 ? "0" : "") + baseDate.getMinutes(); + let humanSecond = + (baseDate.getSeconds() < 10 ? "0" : "") + baseDate.getSeconds(); + let humanMillisecond = + (baseDate.getMilliseconds() < 10 ? "0" : "") + baseDate.getMilliseconds(); + let HumanizedDateTime = + humanYear + "-" + humanMonth + "-" + humanDate + " @" + humanHour + "h " + humanMinute + "m " + humanSecond + "s " + humanMillisecond + "ms"; return HumanizedDateTime; } @@ -74,60 +74,61 @@ export function humanizedDateTime() { // triggers: $("#rm_button_create").on("click", function () { //when "+New Character" is clicked $(SelectedCharacterTab).children("h2").html(''); // empty nav's 3rd panel tab - + //empty temp vars to store new char data for counting - create_save_name=""; - create_save_description=""; - create_save_personality=""; - create_save_first_message=""; - create_save_scenario=""; - create_save_mes_example=""; + create_save_name = ""; + create_save_description = ""; + create_save_personality = ""; + create_save_first_message = ""; + create_save_scenario = ""; + create_save_mes_example = ""; $("#result_info").html('Type to start counting tokens!'); }); -$("#rm_ch_create_block").on("input", function () {RA_CountCharTokens();}); //when any input is made to the create/edit character form textareas -$("#character_popup").on("input", function () {RA_CountCharTokens();}); //when any input is made to the advanced editing popup textareas +$("#rm_ch_create_block").on("input", function () { RA_CountCharTokens(); }); //when any input is made to the create/edit character form textareas +$("#character_popup").on("input", function () { RA_CountCharTokens(); }); //when any input is made to the advanced editing popup textareas //function: function RA_CountCharTokens() { - $("#result_info").html(""); - console.log('RA_TC -- starting with this_chid = '+this_chid); - if (document.getElementById('name_div').style.display == "block"){ //if new char + $("#result_info").html(""); + console.log('RA_TC -- starting with this_chid = ' + this_chid); + if (document.getElementById('name_div').style.display == "block") { //if new char - $("#form_create").on("input", function () { //fill temp vars with form_create values - create_save_name = $("#character_name_pole").val(); - create_save_description = $("#description_textarea").val(); - create_save_first_message = $("#firstmessage_textarea").val(); - }); - $("#character_popup").on("input", function () { //fill temp vars with advanced popup values - create_save_personality = $("#personality_textarea").val(); - create_save_scenario = $("#scenario_pole").val(); - create_save_mes_example = $("#mes_example_textarea").val(); - - }); + $("#form_create").on("input", function () { //fill temp vars with form_create values + create_save_name = $("#character_name_pole").val(); + create_save_description = $("#description_textarea").val(); + create_save_first_message = $("#firstmessage_textarea").val(); + }); + $("#character_popup").on("input", function () { //fill temp vars with advanced popup values + create_save_personality = $("#personality_textarea").val(); + create_save_scenario = $("#scenario_pole").val(); + create_save_mes_example = $("#mes_example_textarea").val(); - //count total tokens, including those that will be removed from context once chat history is long - count_tokens = encode(JSON.stringify( - create_save_name + - create_save_description + - create_save_personality + - create_save_scenario + - create_save_first_message + - create_save_mes_example - )).length; + }); - //count permanent tokens that will never get flushed out of context - perm_tokens = encode(JSON.stringify( - create_save_name + - create_save_description + - create_save_personality + - create_save_scenario - )).length; + //count total tokens, including those that will be removed from context once chat history is long + count_tokens = encode(JSON.stringify( + create_save_name + + create_save_description + + create_save_personality + + create_save_scenario + + create_save_first_message + + create_save_mes_example + )).length; - } else {if (this_chid !== undefined && this_chid !== "invalid-safety-id") { // if we are counting a valid pre-saved char + //count permanent tokens that will never get flushed out of context + perm_tokens = encode(JSON.stringify( + create_save_name + + create_save_description + + create_save_personality + + create_save_scenario + )).length; + + } else { + if (this_chid !== undefined && this_chid !== "invalid-safety-id") { // if we are counting a valid pre-saved char //same as above, all tokens including temporary ones count_tokens = encode( JSON.stringify( - characters[this_chid].description + + characters[this_chid].description + characters[this_chid].personality + characters[this_chid].scenario + characters[this_chid].first_mes + @@ -137,134 +138,134 @@ function RA_CountCharTokens() { //permanent tokens count perm_tokens = encode( JSON.stringify( - characters[this_chid].name + + characters[this_chid].name + characters[this_chid].description + characters[this_chid].personality + characters[this_chid].scenario )).length; - } else {console.log("RA_TC -- no valid char found, closing.");} // if neither, probably safety char or some error in loading - } - // display the counted tokens - if (count_tokens < 1024 && perm_tokens < 1024) { - $("#result_info").html(count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)"); //display normal if both counts are under 1024 - } else {$("#result_info").html("" +count_tokens +" Tokens (" +perm_tokens +" Permanent Tokens)(TOO MANY)");} //warn if either are over 1024 + } else { console.log("RA_TC -- no valid char found, closing."); } // if neither, probably safety char or some error in loading + } + // display the counted tokens + if (count_tokens < 1024 && perm_tokens < 1024) { + $("#result_info").html(count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)"); //display normal if both counts are under 1024 + } else { $("#result_info").html("" + count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)(TOO MANY)"); } //warn if either are over 1024 } //Auto Load Last Charcter -- (fires when active_character is defined and auto_load_chat is true) async function RA_autoloadchat() { - if (document.getElementById('CharID0') !== null){ + if (document.getElementById('CharID0') !== null) { console.log('char list loaded! clicking activeChar') - var CharToAutoLoad = document.getElementById('CharID'+LoadLocal('ActiveChar')); - if (CharToAutoLoad !=null){ + var CharToAutoLoad = document.getElementById('CharID' + LoadLocal('ActiveChar')); + if (CharToAutoLoad != null) { CharToAutoLoad.click(); - }else{ - console.log(CharToAutoLoad + ' ActiveChar local var - not found: '+LoadLocal('ActiveChar')); - } + } else { + console.log(CharToAutoLoad + ' ActiveChar local var - not found: ' + LoadLocal('ActiveChar')); + } RestoreNavTab(); - }else{ + } else { console.log('no char list yet..') - setTimeout(RA_autoloadchat,100) // if the charcter list hadn't been loaded yet, try again. - } -} + setTimeout(RA_autoloadchat, 100) // if the charcter list hadn't been loaded yet, try again. + } +} //only triggers when AutoLoadChat is enabled, consider adding this as an independent feature later. -function RestoreNavTab(){ - if($(rm_button_selected_ch).children("h2").text()!==''){ //check for a change in the character edit tab name +function RestoreNavTab() { + if ($(rm_button_selected_ch).children("h2").text() !== '') { //check for a change in the character edit tab name console.log('detected ALC char finished loaded, proceeding to restore tab.'); $(SelectedNavTab).click() //click to restore saved tab when name has changed (signalling char load is done) - }else{ - setTimeout(RestoreNavTab,100) //if not changed yet, check again after 100ms + } else { + setTimeout(RestoreNavTab, 100) //if not changed yet, check again after 100ms } } //changes input bar and send button display depending on connection status function RA_checkOnlineStatus() { - if (online_status == "no_connection") { - $("#send_textarea").attr("placeholder", "Not connected to API!"); //Input bar placeholder tells users they are not connected - $("#send_form").css("background-color", "rgba(100,0,0,0.7)"); //entire input form area is red when not connected - $("#send_but").css("display", "none"); //send button is hidden when not connected; - } else { - if (online_status !== undefined && online_status !== "no_connection") { - $("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message - $("#send_form").css("background-color", "rgba(0,0,0,0.7)"); //on connect, form BG changes to transprent black + if (online_status == "no_connection") { + $("#send_textarea").attr("placeholder", "Not connected to API!"); //Input bar placeholder tells users they are not connected + $("#send_form").css("background-color", "rgba(100,0,0,0.7)"); //entire input form area is red when not connected + $("#send_but").css("display", "none"); //send button is hidden when not connected; + } else { + if (online_status !== undefined && online_status !== "no_connection") { + $("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message + $("#send_form").css("background-color", "rgba(0,0,0,0.7)"); //on connect, form BG changes to transprent black - if (!is_send_press && !(selected_group && is_group_generating)) { - $("#send_but").css("display", "inline"); //on connect, send button shows - } - } - } + if (!is_send_press && !(selected_group && is_group_generating)) { + $("#send_but").css("display", "inline"); //on connect, send button shows + } + } + } } //Auto-connect to API (when set to kobold, API URL exists, and auto_connect is true) - - function RA_autoconnect() { - if (typeof online_status !== 'undefined' && (api_server !== '' || api_key_novel !== '')) { - if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) { + +function RA_autoconnect() { + if (typeof online_status !== 'undefined' && (api_server !== '' || api_key_novel !== '')) { + if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) { if (isUrlOrAPIKey(api_server) && main_api === "kobold") { - $("#api_url_text").val(api_server); - $("#api_button").click(); - //} else if (isUrlOrAPIKey(api_key_novel) && main_api === "novel") { - // $("#api_key_novel").val(api_key_novel); - // $("#api_button").click(); + $("#api_url_text").val(api_server); + $("#api_button").click(); + //} else if (isUrlOrAPIKey(api_key_novel) && main_api === "novel") { + // $("#api_key_novel").val(api_key_novel); + // $("#api_button").click(); } - } - } else { - setTimeout(RA_autoconnect, 100); } - } - - function isUrlOrAPIKey(string) { - //const pattern = /^\d{3}-\d{3}-\d{3}-\d{3}$/; //need a sample novelAI key to set this format - try { - new URL(string); - return true; - } catch (_) { -// return pattern.test(string); - } - } + } else { + setTimeout(RA_autoconnect, 100); + } +} + +function isUrlOrAPIKey(string) { + //const pattern = /^\d{3}-\d{3}-\d{3}-\d{3}$/; //need a sample novelAI key to set this format + try { + new URL(string); + return true; + } catch (_) { + // return pattern.test(string); + } +} $("document").ready(function () { // read the state of Nav Lock and whether the nav was open or not before page load. $(PanelPin).prop('checked', LoadLocalBool("NavLockOn")); - if (LoadLocalBool("NavLockOn") == true){$(NavToggle).prop("checked", LoadLocalBool("NavOpened"));} + if (LoadLocalBool("NavLockOn") == true) { $(NavToggle).prop("checked", LoadLocalBool("NavOpened")); } // read the state of AutoConnect and AutoLoadChat. - $(AutoConnectCheckbox).prop("checked",LoadLocalBool("AutoConnectEnabled")); - $(AutoLoadChatCheckbox).prop("checked",LoadLocalBool("AutoLoadChatEnabled")); - - if (LoadLocalBool('AutoLoadChatEnabled') == true) {RA_autoloadchat();} + $(AutoConnectCheckbox).prop("checked", LoadLocalBool("AutoConnectEnabled")); + $(AutoLoadChatCheckbox).prop("checked", LoadLocalBool("AutoLoadChatEnabled")); + + if (LoadLocalBool('AutoLoadChatEnabled') == true) { RA_autoloadchat(); } //Autoconnect on page load if enabled, or when api type is changed - if (LoadLocalBool("AutoConnectEnabled") == true) {RA_autoconnect()} - $("#main_api").change(function () {RA_autoconnect();}); - $("#api_button").click(function () {setTimeout(RA_checkOnlineStatus, 100);}); + if (LoadLocalBool("AutoConnectEnabled") == true) { RA_autoconnect() } + $("#main_api").change(function () { RA_autoconnect(); }); + $("#api_button").click(function () { setTimeout(RA_checkOnlineStatus, 100); }); //close the RightNav panel when user clicks outside of it or related panels (adv editing popup, or dialog popups) $("html").click(function (e) { - if ($(NavToggle).prop("checked") && - !$(PanelPin).prop("checked") && - $(e.target).attr("id") !== "nav-toggle" && - !RightNavPanel.contains(e.target) && - !AdvancedCharDefsPopup.contains(e.target) && + if ($(NavToggle).prop("checked") && + !$(PanelPin).prop("checked") && + $(e.target).attr("id") !== "nav-toggle" && + !RightNavPanel.contains(e.target) && + !AdvancedCharDefsPopup.contains(e.target) && !ConfirmationPopup.contains(e.target)) { - NavToggle.click(); + NavToggle.click(); } }); //save NavLock prefs and record state of the Nav being open or closed - $(NavToggle).on("change", function () {SaveLocal("NavOpened", $(NavToggle).prop("checked")); }); - $(PanelPin).on("change",function () {SaveLocal("NavLockOn", $(PanelPin).prop("checked")); }); + $(NavToggle).on("change", function () { SaveLocal("NavOpened", $(NavToggle).prop("checked")); }); + $(PanelPin).on("change", function () { SaveLocal("NavLockOn", $(PanelPin).prop("checked")); }); //save AutoConnect and AutoLoadChat prefs - $(AutoConnectCheckbox).on("change",function () {SaveLocal("AutoConnectEnabled", $(AutoConnectCheckbox).prop("checked")); }); - $(AutoLoadChatCheckbox).on("change",function () {SaveLocal("AutoLoadChatEnabled", $(AutoLoadChatCheckbox).prop("checked")); }); + $(AutoConnectCheckbox).on("change", function () { SaveLocal("AutoConnectEnabled", $(AutoConnectCheckbox).prop("checked")); }); + $(AutoLoadChatCheckbox).on("change", function () { SaveLocal("AutoLoadChatEnabled", $(AutoLoadChatCheckbox).prop("checked")); }); - $("#rm_button_extensions").click(function() { - SaveLocal('SelectedNavTab','rm_button_extensions'); - }); - $("#rm_button_settings").click( function (){SaveLocal('SelectedNavTab','rm_button_settings'); }); - $(SelectedCharacterTab).click(function () {SaveLocal('SelectedNavTab','rm_button_selected_ch'); }); - $("#rm_button_characters").click( function () { //if char list is clicked, in addition to saving it... - SaveLocal('SelectedNavTab','rm_button_characters'); + $("#rm_button_extensions").click(function () { + SaveLocal('SelectedNavTab', 'rm_button_extensions'); + }); + $("#rm_button_settings").click(function () { SaveLocal('SelectedNavTab', 'rm_button_settings'); }); + $(SelectedCharacterTab).click(function () { SaveLocal('SelectedNavTab', 'rm_button_selected_ch'); }); + $("#rm_button_characters").click(function () { //if char list is clicked, in addition to saving it... + SaveLocal('SelectedNavTab', 'rm_button_characters'); characters.sort(Intl.Collator().compare); // we sort the list }); // when a char is selected from the list, save them as the auto-load character for next page load - $(document).on("click", ".character_select",function () {SaveLocal('ActiveChar',$(this).attr('chid')); }); + $(document).on("click", ".character_select", function () { SaveLocal('ActiveChar', $(this).attr('chid')); }); //this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height) $('#send_textarea').on('input', function () { @@ -274,20 +275,20 @@ $("document").ready(function () { //Regenerate if user swipes on the last mesage in chat - document.addEventListener('swiped-left', function(e) { + document.addEventListener('swiped-left', function (e) { var SwipeButR = $('.swipe_right:last'); var SwipeTargetMesClassParent = e.target.closest('.last_mes'); - if (SwipeTargetMesClassParent !== null){ - if(SwipeButR.attr('style')=='display: flex;' == true){ + if (SwipeTargetMesClassParent !== null) { + if (SwipeButR.attr('style') == 'display: flex;' == true) { SwipeButR.click(); } } }); - document.addEventListener('swiped-right', function(e) { + document.addEventListener('swiped-right', function (e) { var SwipeButL = $('.swipe_left:last'); var SwipeTargetMesClassParent = e.target.closest('.last_mes'); - if (SwipeTargetMesClassParent !== null){ - if(SwipeButL.attr('style')=='display: flex;' == true){ + if (SwipeTargetMesClassParent !== null) { + if (SwipeButL.attr('style') == 'display: flex;' == true) { SwipeButL.click(); } } @@ -296,16 +297,16 @@ $("document").ready(function () { //Additional hotkeys CTRL+ENTER and CTRL+UPARROW document.addEventListener("keydown", (event) => { if (event.ctrlKey && event.key == "Enter") { - // Ctrl+Enter for Regeneration Last Response + // Ctrl+Enter for Regeneration Last Response if (is_send_press == false) { Generate("regenerate"); - } + } } if (event.ctrlKey && event.key == "ArrowUp") { //Ctrl+UpArrow for Connect to last server if (online_status === "no_connection") { - document.getElementById("api_button").click(); + document.getElementById("api_button").click(); } } if (event.ctrlKey && event.key == "ArrowLeft") { //for debug, show all local stored vars @@ -321,5 +322,5 @@ $("document").ready(function () { $('.swipe_right:last').click(); } }); - + })