Restore last active group

This commit is contained in:
SillyLossy
2023-03-28 22:58:36 +03:00
parent 9d512e09bc
commit 6ab38964dc
2 changed files with 325 additions and 310 deletions

View File

@@ -2,21 +2,21 @@ esversion: 6
import { encode } from "../scripts/gpt-2-3-tokenizer/mod.js"; import { encode } from "../scripts/gpt-2-3-tokenizer/mod.js";
import { import {
Generate, Generate,
this_chid, this_chid,
characters, characters,
online_status, online_status,
main_api, main_api,
api_server, api_server,
nai_settings, nai_settings,
api_server_textgenerationwebui, api_server_textgenerationwebui,
is_send_press, is_send_press,
} from "../script.js"; } from "../script.js";
import { import {
fast_ui_mode, fast_ui_mode,
pin_examples, pin_examples,
} from "./power-user.js"; } from "./power-user.js";
import { LoadLocal, SaveLocal, ClearLocal, CheckLocal, LoadLocalBool } from "./f-localStorage.js"; import { LoadLocal, SaveLocal, ClearLocal, CheckLocal, LoadLocalBool } from "./f-localStorage.js";
@@ -49,15 +49,15 @@ var RA_AC_retries = 1;
const observerConfig = { childList: true, subtree: true }; const observerConfig = { childList: true, subtree: true };
const observer = new MutationObserver(function (mutations) { const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) { mutations.forEach(function (mutation) {
if (mutation.target.id === "online_status_text2" || if (mutation.target.id === "online_status_text2" ||
mutation.target.id === "online_status_text3" || mutation.target.id === "online_status_text3" ||
mutation.target.classList.contains("online_status_text4")) { mutation.target.classList.contains("online_status_text4")) {
RA_checkOnlineStatus(); RA_checkOnlineStatus();
} else if (mutation.target.parentNode === SelectedCharacterTab) { } else if (mutation.target.parentNode === SelectedCharacterTab) {
setTimeout(RA_CountCharTokens, 200); setTimeout(RA_CountCharTokens, 200);
} }
}); });
}); });
observer.observe(document.documentElement, observerConfig); observer.observe(document.documentElement, observerConfig);
@@ -68,360 +68,374 @@ observer.observe(document.documentElement, observerConfig);
//Does not break old characters/chats, as the code just uses whatever timestamp exists in the chat. //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. //New chats made with characters will use this new formatting.
export function humanizedDateTime() { export function humanizedDateTime() {
let baseDate = new Date(Date.now()); let baseDate = new Date(Date.now());
let humanYear = baseDate.getFullYear(); let humanYear = baseDate.getFullYear();
let humanMonth = baseDate.getMonth() + 1; let humanMonth = baseDate.getMonth() + 1;
let humanDate = baseDate.getDate(); let humanDate = baseDate.getDate();
let humanHour = (baseDate.getHours() < 10 ? "0" : "") + baseDate.getHours(); let humanHour = (baseDate.getHours() < 10 ? "0" : "") + baseDate.getHours();
let humanMinute = let humanMinute =
(baseDate.getMinutes() < 10 ? "0" : "") + baseDate.getMinutes(); (baseDate.getMinutes() < 10 ? "0" : "") + baseDate.getMinutes();
let humanSecond = let humanSecond =
(baseDate.getSeconds() < 10 ? "0" : "") + baseDate.getSeconds(); (baseDate.getSeconds() < 10 ? "0" : "") + baseDate.getSeconds();
let humanMillisecond = let humanMillisecond =
(baseDate.getMilliseconds() < 10 ? "0" : "") + baseDate.getMilliseconds(); (baseDate.getMilliseconds() < 10 ? "0" : "") + baseDate.getMilliseconds();
let HumanizedDateTime = let HumanizedDateTime =
humanYear + "-" + humanMonth + "-" + humanDate + " @" + humanHour + "h " + humanMinute + "m " + humanSecond + "s " + humanMillisecond + "ms"; humanYear + "-" + humanMonth + "-" + humanDate + " @" + humanHour + "h " + humanMinute + "m " + humanSecond + "s " + humanMillisecond + "ms";
return HumanizedDateTime; return HumanizedDateTime;
} }
// triggers: // triggers:
$("#rm_button_create").on("click", function () { //when "+New Character" is clicked $("#rm_button_create").on("click", function () { //when "+New Character" is clicked
$(SelectedCharacterTab).children("h2").html(''); // empty nav's 3rd panel tab $(SelectedCharacterTab).children("h2").html(''); // empty nav's 3rd panel tab
//empty temp vars to store new char data for counting //empty temp vars to store new char data for counting
create_save_name = ""; create_save_name = "";
create_save_description = ""; create_save_description = "";
create_save_personality = ""; create_save_personality = "";
create_save_first_message = ""; create_save_first_message = "";
create_save_scenario = ""; create_save_scenario = "";
create_save_mes_example = ""; create_save_mes_example = "";
$("#result_info").html('Type to start counting tokens!'); $("#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 $("#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 $("#character_popup").on("input", function () { RA_CountCharTokens(); }); //when any input is made to the advanced editing popup textareas
//function: //function:
function RA_CountCharTokens() { function RA_CountCharTokens() {
$("#result_info").html(""); $("#result_info").html("");
//console.log('RA_TC -- starting with this_chid = ' + this_chid); //console.log('RA_TC -- starting with this_chid = ' + this_chid);
if (document.getElementById('name_div').style.display == "block") { //if new char if (document.getElementById('name_div').style.display == "block") { //if new char
$("#form_create").on("input", function () { //fill temp vars with form_create values $("#form_create").on("input", function () { //fill temp vars with form_create values
create_save_name = $("#character_name_pole").val(); create_save_name = $("#character_name_pole").val();
create_save_description = $("#description_textarea").val(); create_save_description = $("#description_textarea").val();
create_save_first_message = $("#firstmessage_textarea").val(); create_save_first_message = $("#firstmessage_textarea").val();
}); });
$("#character_popup").on("input", function () { //fill temp vars with advanced popup values $("#character_popup").on("input", function () { //fill temp vars with advanced popup values
create_save_personality = $("#personality_textarea").val(); create_save_personality = $("#personality_textarea").val();
create_save_scenario = $("#scenario_pole").val(); create_save_scenario = $("#scenario_pole").val();
create_save_mes_example = $("#mes_example_textarea").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 total tokens, including those that will be removed from context once chat history is long
count_tokens = encode(JSON.stringify( count_tokens = encode(JSON.stringify(
create_save_name + create_save_name +
create_save_description + create_save_description +
create_save_personality + create_save_personality +
create_save_scenario + create_save_scenario +
create_save_first_message + create_save_first_message +
create_save_mes_example create_save_mes_example
)).length; )).length;
//count permanent tokens that will never get flushed out of context //count permanent tokens that will never get flushed out of context
perm_tokens = encode(JSON.stringify( perm_tokens = encode(JSON.stringify(
create_save_name + create_save_name +
create_save_description + create_save_description +
create_save_personality + create_save_personality +
create_save_scenario create_save_scenario
)).length; )).length;
} else { } else {
if (this_chid !== undefined && this_chid !== "invalid-safety-id") { // if we are counting a valid pre-saved char 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 //same as above, all tokens including temporary ones
count_tokens = encode( count_tokens = encode(
JSON.stringify( JSON.stringify(
characters[this_chid].description + characters[this_chid].description +
characters[this_chid].personality + characters[this_chid].personality +
characters[this_chid].scenario + characters[this_chid].scenario +
characters[this_chid].first_mes + characters[this_chid].first_mes +
characters[this_chid].mes_example characters[this_chid].mes_example
)).length; )).length;
//permanent tokens count //permanent tokens count
perm_tokens = encode( perm_tokens = encode(
JSON.stringify( JSON.stringify(
characters[this_chid].name + characters[this_chid].name +
characters[this_chid].description + characters[this_chid].description +
characters[this_chid].personality + characters[this_chid].personality +
characters[this_chid].scenario + characters[this_chid].scenario +
(pin_examples ? characters[this_chid].mes_example : '') // add examples to permanent if they are pinned (pin_examples ? characters[this_chid].mes_example : '') // add examples to permanent if they are pinned
)).length; )).length;
} else { console.log("RA_TC -- no valid char found, closing."); } // if neither, probably safety char or some error in loading } else { console.log("RA_TC -- no valid char found, closing."); } // if neither, probably safety char or some error in loading
} }
// display the counted tokens // display the counted tokens
if (count_tokens < 1024 && perm_tokens < 1024) { 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 $("#result_info").html(count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)"); //display normal if both counts are under 1024
} else { $("#result_info").html("<font color=red>" + count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)(TOO MANY)</font>"); } //warn if either are over 1024 } else { $("#result_info").html("<font color=red>" + count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)(TOO MANY)</font>"); } //warn if either are over 1024
} }
//Auto Load Last Charcter -- (fires when active_character is defined and auto_load_chat is true) //Auto Load Last Charcter -- (fires when active_character is defined and auto_load_chat is true)
async function RA_autoloadchat() { async function RA_autoloadchat() {
if (document.getElementById('CharID0') !== null) { if (document.getElementById('CharID0') !== null) {
//console.log('char list loaded! clicking activeChar'); //console.log('char list loaded! clicking activeChar');
var CharToAutoLoad = document.getElementById('CharID' + LoadLocal('ActiveChar')); var CharToAutoLoad = document.getElementById('CharID' + LoadLocal('ActiveChar'));
if (CharToAutoLoad != null) { let autoLoadGroup = document.querySelector(`.group_select[grid="${LoadLocal('ActiveGroup')}"]`);
CharToAutoLoad.click(); if (CharToAutoLoad != null) {
} else { CharToAutoLoad.click();
console.log(CharToAutoLoad + ' ActiveChar local var - not found: ' + LoadLocal('ActiveChar')); }
} else if (autoLoadGroup != null) {
RestoreNavTab(); autoLoadGroup.click();
} else { }
//console.log('no char list yet..'); else {
setTimeout(RA_autoloadchat, 100); // if the charcter list hadn't been loaded yet, try again. console.log(CharToAutoLoad + ' ActiveChar local var - not found: ' + LoadLocal('ActiveChar'));
} }
RestoreNavTab();
} else {
//console.log('no char list yet..');
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. //only triggers when AutoLoadChat is enabled, consider adding this as an independent feature later.
function RestoreNavTab() { function RestoreNavTab() {
if ($('#rm_button_selected_ch').children("h2").text() !== '') { //check for a change in the character edit tab name 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.'); //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) $(SelectedNavTab).click(); //click to restore saved tab when name has changed (signalling char load is done)
} else { } else {
setTimeout(RestoreNavTab, 100); //if not changed yet, check again after 100ms setTimeout(RestoreNavTab, 100); //if not changed yet, check again after 100ms
} }
} }
//changes input bar and send button display depending on connection status //changes input bar and send button display depending on connection status
function RA_checkOnlineStatus() { function RA_checkOnlineStatus() {
if (online_status == "no_connection") { if (online_status == "no_connection") {
$("#send_textarea").attr("placeholder", "Not connected to API!"); //Input bar placeholder tells users they are not connected $("#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.5)"); //entire input form area is red when not connected $("#send_form").css("background-color", "rgba(100,0,0,0.5)"); //entire input form area is red when not connected
$("#send_but").css("display", "none"); //send button is hidden when not connected; $("#send_but").css("display", "none"); //send button is hidden when not connected;
$("#API-status-top").addClass("redOverlayGlow"); $("#API-status-top").addClass("redOverlayGlow");
connection_made = false; connection_made = false;
} else { } else {
if (online_status !== undefined && online_status !== "no_connection") { if (online_status !== undefined && online_status !== "no_connection") {
$("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message $("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message
const formColor = fast_ui_mode ? "var(--black90a)": "var(--black60a)"; const formColor = fast_ui_mode ? "var(--black90a)" : "var(--black60a)";
$("#send_form").css("background-color", formColor); //on connect, form BG changes to transprent black $("#send_form").css("background-color", formColor); //on connect, form BG changes to transprent black
$("#API-status-top").removeClass("redOverlayGlow"); $("#API-status-top").removeClass("redOverlayGlow");
connection_made = true; connection_made = true;
retry_delay = 100; retry_delay = 100;
RA_AC_retries = 1; RA_AC_retries = 1;
if (!is_send_press && !(selected_group && is_group_generating)) { if (!is_send_press && !(selected_group && is_group_generating)) {
$("#send_but").css("display", "inline"); //on connect, send button shows $("#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) //Auto-connect to API (when set to kobold, API URL exists, and auto_connect is true)
function RA_autoconnect(PrevApi) { function RA_autoconnect(PrevApi) {
if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) { if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) {
switch (main_api) { switch (main_api) {
case 'kobold': case 'kobold':
if (api_server && isUrlOrAPIKey(api_server)) { if (api_server && isUrlOrAPIKey(api_server)) {
$("#api_button").click(); $("#api_button").click();
} }
break; break;
case 'novel': case 'novel':
if (nai_settings.api_key_novel) { if (nai_settings.api_key_novel) {
$("#api_button_novel").click(); $("#api_button_novel").click();
} }
break; break;
case 'textgenerationwebui': case 'textgenerationwebui':
if (api_server_textgenerationwebui && isUrlOrAPIKey(api_server_textgenerationwebui)) { if (api_server_textgenerationwebui && isUrlOrAPIKey(api_server_textgenerationwebui)) {
$("#api_button_textgenerationwebui").click(); $("#api_button_textgenerationwebui").click();
} }
break; break;
case 'openai': case 'openai':
if (oai_settings.api_key_openai) { if (oai_settings.api_key_openai) {
$("#api_button_openai").click(); $("#api_button_openai").click();
} }
} }
if (!connection_made) { if (!connection_made) {
RA_AC_retries++; RA_AC_retries++;
retry_delay = Math.min(retry_delay * 2, 30000); // double retry delay up to to 30 secs retry_delay = Math.min(retry_delay * 2, 30000); // double retry delay up to to 30 secs
//console.log('connection attempts: ' + RA_AC_retries + ' delay: ' + (retry_delay / 1000) + 's'); //console.log('connection attempts: ' + RA_AC_retries + ' delay: ' + (retry_delay / 1000) + 's');
setTimeout(RA_autoconnect, retry_delay); setTimeout(RA_autoconnect, retry_delay);
} }
} }
} }
function isUrlOrAPIKey(string) { function isUrlOrAPIKey(string) {
try { try {
new URL(string); new URL(string);
return true; return true;
} catch (_) { } catch (_) {
// return pattern.test(string); // return pattern.test(string);
} }
} }
$("document").ready(function () { $("document").ready(function () {
// initial status check // initial status check
setTimeout(RA_checkOnlineStatus, 100); setTimeout(RA_checkOnlineStatus, 100);
// read the state of AutoConnect and AutoLoadChat. // read the state of AutoConnect and AutoLoadChat.
$(AutoConnectCheckbox).prop("checked", LoadLocalBool("AutoConnectEnabled")); $(AutoConnectCheckbox).prop("checked", LoadLocalBool("AutoConnectEnabled"));
$(AutoLoadChatCheckbox).prop("checked", LoadLocalBool("AutoLoadChatEnabled")); $(AutoLoadChatCheckbox).prop("checked", LoadLocalBool("AutoLoadChatEnabled"));
if (LoadLocalBool('AutoLoadChatEnabled') == true) { RA_autoloadchat(); } if (LoadLocalBool('AutoLoadChatEnabled') == true) { RA_autoloadchat(); }
//Autoconnect on page load if enabled, or when api type is changed //Autoconnect on page load if enabled, or when api type is changed
if (LoadLocalBool("AutoConnectEnabled") == true) { RA_autoconnect(); } if (LoadLocalBool("AutoConnectEnabled") == true) { RA_autoconnect(); }
$("#main_api").change(function () { $("#main_api").change(function () {
var PrevAPI = main_api; var PrevAPI = main_api;
RA_autoconnect(PrevAPI); RA_autoconnect(PrevAPI);
}); });
$("#api_button").click(function () { setTimeout(RA_checkOnlineStatus, 100); }); $("#api_button").click(function () { setTimeout(RA_checkOnlineStatus, 100); });
//toggle pin class when lock toggle clicked //toggle pin class when lock toggle clicked
$(PanelPin).on("click", function () { $(PanelPin).on("click", function () {
SaveLocal("NavLockOn", $(PanelPin).prop("checked")); SaveLocal("NavLockOn", $(PanelPin).prop("checked"));
if ($(PanelPin).prop("checked") == true) { if ($(PanelPin).prop("checked") == true) {
console.log('adding pin class to right nav'); console.log('adding pin class to right nav');
$(RightNavPanel).addClass('pinnedOpen'); $(RightNavPanel).addClass('pinnedOpen');
} else { } else {
console.log('removing pin class from right nav'); console.log('removing pin class from right nav');
$(RightNavPanel).removeClass('pinnedOpen'); $(RightNavPanel).removeClass('pinnedOpen');
if ($(RightNavPanel).hasClass('openDrawer') && $('.openDrawer').length > 1) { if ($(RightNavPanel).hasClass('openDrawer') && $('.openDrawer').length > 1) {
$(RightNavPanel).slideToggle(200, "swing"); $(RightNavPanel).slideToggle(200, "swing");
$(rightNavDrawerIcon).toggleClass('openIcon closedIcon'); $(rightNavDrawerIcon).toggleClass('openIcon closedIcon');
$(RightNavPanel).toggleClass('openDrawer closedDrawer'); $(RightNavPanel).toggleClass('openDrawer closedDrawer');
} }
} }
}); });
// read the state of Nav Lock and apply to rightnav classlist // read the state of Nav Lock and apply to rightnav classlist
$(PanelPin).prop('checked', LoadLocalBool("NavLockOn")); $(PanelPin).prop('checked', LoadLocalBool("NavLockOn"));
if (LoadLocalBool("NavLockOn") == true) { if (LoadLocalBool("NavLockOn") == true) {
//console.log('setting pin class via local var'); //console.log('setting pin class via local var');
$(RightNavPanel).addClass('pinnedOpen'); $(RightNavPanel).addClass('pinnedOpen');
} }
if ($(PanelPin).prop('checked' == true)) { if ($(PanelPin).prop('checked' == true)) {
console.log('setting pin class via checkbox state'); console.log('setting pin class via checkbox state');
$(RightNavPanel).addClass('pinnedOpen'); $(RightNavPanel).addClass('pinnedOpen');
} }
//save state of nav being open or closed //save state of nav being open or closed
$("#rightNavDrawerIcon").on("click", function () { $("#rightNavDrawerIcon").on("click", function () {
if (!$("#rightNavDrawerIcon").hasClass('openIcon')) { if (!$("#rightNavDrawerIcon").hasClass('openIcon')) {
SaveLocal('NavOpened', 'true'); SaveLocal('NavOpened', 'true');
} else { SaveLocal('NavOpened', 'false'); } } else { SaveLocal('NavOpened', 'false'); }
}); });
if (LoadLocalBool("NavLockOn") == true && LoadLocalBool("NavOpened") == true) { if (LoadLocalBool("NavLockOn") == true && LoadLocalBool("NavOpened") == true) {
$("#rightNavDrawerIcon").click(); $("#rightNavDrawerIcon").click();
} else { } else {
console.log('didnt see reason to open nav on load: ' + console.log('didnt see reason to open nav on load: ' +
LoadLocalBool("NavLockOn") LoadLocalBool("NavLockOn")
+ ' nav open pref' + + ' nav open pref' +
LoadLocalBool("NavOpened" == true)); LoadLocalBool("NavOpened" == true));
} }
//save AutoConnect and AutoLoadChat prefs //save AutoConnect and AutoLoadChat prefs
$(AutoConnectCheckbox).on("change", function () { SaveLocal("AutoConnectEnabled", $(AutoConnectCheckbox).prop("checked")); }); $(AutoConnectCheckbox).on("change", function () { SaveLocal("AutoConnectEnabled", $(AutoConnectCheckbox).prop("checked")); });
$(AutoLoadChatCheckbox).on("change", function () { SaveLocal("AutoLoadChatEnabled", $(AutoLoadChatCheckbox).prop("checked")); }); $(AutoLoadChatCheckbox).on("change", function () { SaveLocal("AutoLoadChatEnabled", $(AutoLoadChatCheckbox).prop("checked")); });
$(SelectedCharacterTab).click(function () { SaveLocal('SelectedNavTab', 'rm_button_selected_ch'); }); $(SelectedCharacterTab).click(function () { SaveLocal('SelectedNavTab', 'rm_button_selected_ch'); });
$("#rm_button_characters").click(function () { //if char list is clicked, in addition to saving it... $("#rm_button_characters").click(function () { //if char list is clicked, in addition to saving it...
SaveLocal('SelectedNavTab', 'rm_button_characters'); SaveLocal('SelectedNavTab', 'rm_button_characters');
characters.sort(Intl.Collator().compare); // we sort the list 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')); });
//this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height) // when a char is selected from the list, save them as the auto-load character for next page load
$('#send_textarea').on('input', function () { $(document).on("click", ".character_select", function () {
this.style.height = '40px'; SaveLocal('ActiveChar', $(this).attr('chid'));
this.style.height = (this.scrollHeight) + 'px'; SaveLocal('ActiveGroup', null);
}); });
//Regenerate if user swipes on the last mesage in chat $(document).on("click", ".group_select", function () {
SaveLocal('ActiveChar', null);
SaveLocal('ActiveGroup', $(this).data('id'));
});
document.addEventListener('swiped-left', function (e) { //this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
var SwipeButR = $('.swipe_right:last'); $('#send_textarea').on('input', function () {
var SwipeTargetMesClassParent = e.target.closest('.last_mes'); this.style.height = '40px';
if (SwipeTargetMesClassParent !== null) { this.style.height = (this.scrollHeight) + 'px';
if (SwipeButR.css('display') === 'flex') { });
SwipeButR.click();
}
}
});
document.addEventListener('swiped-right', function (e) {
var SwipeButL = $('.swipe_left:last');
var SwipeTargetMesClassParent = e.target.closest('.last_mes');
if (SwipeTargetMesClassParent !== null) {
if (SwipeButL.css('display') === 'flex') {
SwipeButL.click();
}
}
});
function isInputElementInFocus() { //Regenerate if user swipes on the last mesage in chat
return $(document.activeElement).is(":input");
}
//Additional hotkeys CTRL+ENTER and CTRL+UPARROW document.addEventListener('swiped-left', function (e) {
document.addEventListener("keydown", (event) => { var SwipeButR = $('.swipe_right:last');
if (event.ctrlKey && event.key == "Enter") { var SwipeTargetMesClassParent = e.target.closest('.last_mes');
// Ctrl+Enter for Regeneration Last Response if (SwipeTargetMesClassParent !== null) {
if (is_send_press == false) { if (SwipeButR.css('display') === 'flex') {
SwipeButR.click();
}
}
});
document.addEventListener('swiped-right', function (e) {
var SwipeButL = $('.swipe_left:last');
var SwipeTargetMesClassParent = e.target.closest('.last_mes');
if (SwipeTargetMesClassParent !== null) {
if (SwipeButL.css('display') === 'flex') {
SwipeButL.click();
}
}
});
$('#option_regenerate').click(); function isInputElementInFocus() {
$('#options').hide(); return $(document.activeElement).is(":input");
//setTimeout(function () { $('#chat').click(); }, 50) //needed to remove the options menu popping up.. }
//Generate("regenerate");
} //Additional hotkeys CTRL+ENTER and CTRL+UPARROW
} document.addEventListener("keydown", (event) => {
if (event.ctrlKey && event.key == "ArrowUp") { if (event.ctrlKey && event.key == "Enter") {
//Ctrl+UpArrow for Connect to last server // Ctrl+Enter for Regeneration Last Response
console.log(main_api); if (is_send_press == false) {
if (online_status === "no_connection") {
if (main_api == "kobold") { $('#option_regenerate').click();
document.getElementById("api_button").click(); $('#options').hide();
} //setTimeout(function () { $('#chat').click(); }, 50) //needed to remove the options menu popping up..
if (main_api == "novel") { //Generate("regenerate");
document.getElementById("api_button_novel").click(); }
} }
if (main_api == "textgenerationwebui") { if (event.ctrlKey && event.key == "ArrowUp") {
document.getElementById("api_button_textgenerationwebui").click(); //Ctrl+UpArrow for Connect to last server
} console.log(main_api);
} if (online_status === "no_connection") {
} if (main_api == "kobold") {
if (event.ctrlKey && event.key == "ArrowLeft") { //for debug, show all local stored vars document.getElementById("api_button").click();
CheckLocal(); }
} if (main_api == "novel") {
if (event.ctrlKey && event.key == "ArrowRight") { //for debug, empty local storage state document.getElementById("api_button_novel").click();
ClearLocal(); }
} if (main_api == "textgenerationwebui") {
if (event.key == "ArrowLeft") { //swipes left document.getElementById("api_button_textgenerationwebui").click();
if ( }
$(".swipe_left:last").css('display') === 'flex' && }
$("#send_textarea").val() === '' && }
$("#character_popup").css("display") === "none" && if (event.ctrlKey && event.key == "ArrowLeft") { //for debug, show all local stored vars
$("#shadow_select_chat_popup").css("display") === "none" && CheckLocal();
!isInputElementInFocus() }
) { if (event.ctrlKey && event.key == "ArrowRight") { //for debug, empty local storage state
$('.swipe_left:last').click(); ClearLocal();
} }
} if (event.key == "ArrowLeft") { //swipes left
if (event.key == "ArrowRight") { //swipes right if (
if ( $(".swipe_left:last").css('display') === 'flex' &&
$(".swipe_right:last").css('display') === 'flex' && $("#send_textarea").val() === '' &&
$("#send_textarea").val() === '' && $("#character_popup").css("display") === "none" &&
$("#character_popup").css("display") === "none" && $("#shadow_select_chat_popup").css("display") === "none" &&
$("#shadow_select_chat_popup").css("display") === "none" && !isInputElementInFocus()
!isInputElementInFocus() ) {
) { $('.swipe_left:last').click();
$('.swipe_right:last').click(); }
} }
} if (event.key == "ArrowRight") { //swipes right
}); if (
$(".swipe_right:last").css('display') === 'flex' &&
$("#send_textarea").val() === '' &&
$("#character_popup").css("display") === "none" &&
$("#shadow_select_chat_popup").css("display") === "none" &&
!isInputElementInFocus()
) {
$('.swipe_right:last').click();
}
}
});
}); });

View File

@@ -180,6 +180,7 @@ function printGroups() {
for (let group of groups) { for (let group of groups) {
const template = $("#group_list_template .group_select").clone(); const template = $("#group_list_template .group_select").clone();
template.data("id", group.id); template.data("id", group.id);
template.attr("grid", group.id);
template.find(".ch_name").text(group.name); template.find(".ch_name").text(group.name);
$("#rm_print_characters_block").prepend(template); $("#rm_print_characters_block").prepend(template);
updateGroupAvatar(group); updateGroupAvatar(group);