Add checkbox for restoring user input on page refresh

This commit is contained in:
Cohee 2023-11-28 00:29:34 +02:00
parent d263760b25
commit 87707b565f
3 changed files with 31 additions and 1 deletions

View File

@ -2950,6 +2950,10 @@
<input id="world_import_dialog" type="checkbox" />
<span data-i18n="Lorebook Import Dialog">Lorebook Import Dialog</span>
</label>
<label class="checkbox_label" for="restore_user_input" title="Restore unsaved user input on page refresh">
<input id="restore_user_input" type="checkbox" />
<span data-i18n="Restore User Input">Restore User Input</span>
</label>
<label data-newbie-hidden id="movingUIModeCheckBlock" for="movingUImode" class="checkbox_label">
<input id="movingUImode" type="checkbox" />
<span data-i18n="Movable UI Panels">MovingUI</span>

View File

@ -460,6 +460,22 @@ function OpenNavPanels() {
}
}
function restoreUserInput() {
if (!power_user.restore_user_input) {
console.debug('restoreUserInput disabled');
return;
}
const userInput = LoadLocal("userInput");
if (userInput) {
$("#send_textarea").val(userInput).trigger('input');
}
}
function saveUserInput() {
const userInput = String($("#send_textarea").val());
SaveLocal("userInput", userInput);
}
// Make the DIV element draggable:
@ -895,11 +911,14 @@ export function initRossMods() {
const chatBlock = $('#chat');
const originalScrollBottom = chatBlock[0].scrollHeight - (chatBlock.scrollTop() + chatBlock.outerHeight());
this.style.height = window.getComputedStyle(this).getPropertyValue('min-height');
this.style.height = (this.scrollHeight) + 'px';
this.style.height = this.scrollHeight + 0.1 + 'px';
const newScrollTop = Math.round(chatBlock[0].scrollHeight - (chatBlock.outerHeight() + originalScrollBottom));
chatBlock.scrollTop(newScrollTop);
saveUserInput();
});
restoreUserInput();
//Regenerate if user swipes on the last mesage in chat
document.addEventListener('swiped-left', function (e) {

View File

@ -223,6 +223,7 @@ let power_user = {
servers: [],
bogus_folders: false,
aux_field: 'character_version',
restore_user_input: true,
};
let themes = [];
@ -1380,6 +1381,7 @@ function loadPowerUserSettings(settings, data) {
$('#chat_width_slider').val(power_user.chat_width);
$("#token_padding").val(power_user.token_padding);
$("#aux_field").val(power_user.aux_field);
$("#restore_user_input").prop("checked", power_user.restore_user_input);
$("#chat_truncation").val(power_user.chat_truncation);
$('#chat_truncation_counter').val(power_user.chat_truncation);
@ -3054,6 +3056,11 @@ $(document).ready(() => {
printCharacters(false);
});
$('#restore_user_input').on('input', function () {
power_user.restore_user_input = !!$(this).prop('checked');
saveSettingsDebounced();
});
$(document).on('click', '#debug_table [data-debug-function]', function () {
const functionId = $(this).data('debug-function');
const functionRecord = debug_functions.find(f => f.functionId === functionId);