From d0650e6910714fbdd2e09c8741aeaa08f911134c Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:09:25 +0300 Subject: [PATCH] Clean-up QR code --- .../scripts/extensions/quick-reply/index.js | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/public/scripts/extensions/quick-reply/index.js b/public/scripts/extensions/quick-reply/index.js index 5e874bd28..5c0ccb7aa 100644 --- a/public/scripts/extensions/quick-reply/index.js +++ b/public/scripts/extensions/quick-reply/index.js @@ -1,8 +1,7 @@ import { saveSettingsDebounced, callPopup, getRequestHeaders, substituteParams } from "../../../script.js"; import { getContext, extension_settings } from "../../extensions.js"; import { initScrollHeight, resetScrollHeight } from "../../utils.js"; -import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "../../slash-commands.js"; - +import { registerSlashCommand } from "../../slash-commands.js"; export { MODULE_NAME }; @@ -17,7 +16,7 @@ const defaultSettings = { quickReplySlots: [], placeBeforeInputEnabled: false, quickActionEnabled: false, - AutoInputInject: true + AutoInputInject: true, } //method from worldinfo @@ -36,8 +35,12 @@ async function updateQuickReplyPresetList() { if (presets !== undefined) { - presets.forEach((item, i) => { - $("#quickReplyPresets").append(``); + presets.forEach((item) => { + const option = document.createElement('option'); + option.value = item.name; + option.innerText = item.name; + option.selected = selected_preset.includes(item.name); + $("#quickReplyPresets").append(option); }); } } @@ -51,6 +54,10 @@ async function loadSettings(type) { Object.assign(extension_settings.quickReply, defaultSettings); } + if (extension_settings.quickReply.AutoInputInject === undefined) { + extension_settings.quickReply.AutoInputInject = true; + } + // If the user has an old version of the extension, update it if (!Array.isArray(extension_settings.quickReply.quickReplySlots)) { extension_settings.quickReply.quickReplySlots = []; @@ -85,14 +92,14 @@ async function loadSettings(type) { function onQuickReplyInput(id) { extension_settings.quickReply.quickReplySlots[id - 1].mes = $(`#quickReply${id}Mes`).val(); - $(`#quickReply${id}`).attr('title', ($(`#quickReply${id}Mes`).val())); + $(`#quickReply${id}`).attr('title', String($(`#quickReply${id}Mes`).val())); resetScrollHeight($(`#quickReply${id}Mes`)); saveSettingsDebounced(); } function onQuickReplyLabelInput(id) { extension_settings.quickReply.quickReplySlots[id - 1].label = $(`#quickReply${id}Label`).val(); - $(`#quickReply${id}`).text($(`#quickReply${id}Label`).val()); + $(`#quickReply${id}`).text(String($(`#quickReply${id}Label`).val())); saveSettingsDebounced(); } @@ -132,7 +139,7 @@ async function sendQuickReply(index) { let newText; - if (existingText && extension_settings.quickReply.AutoInputInject){ + if (existingText && extension_settings.quickReply.AutoInputInject) { if (extension_settings.quickReply.placeBeforeInputEnabled) { newText = `${prompt} ${existingText} `; } else { @@ -148,9 +155,9 @@ async function sendQuickReply(index) { $("#send_textarea").val(newText); // Set the focus back to the textarea - $("#send_textarea").focus(); + $("#send_textarea").trigger('focus'); - // Only trigger send button if quickActionEnabled is not checked or + // Only trigger send button if quickActionEnabled is not checked or // the prompt starts with '/' if (!extension_settings.quickReply.quickActionEnabled || prompt.startsWith('/')) { $("#send_but").trigger('click'); @@ -227,7 +234,7 @@ async function saveQuickReplyPreset() { } else { presets[quickReplyPresetIndex] = quickReplyPreset; - $(`#quickReplyPresets option[value="${name}"]`).attr('selected', true); + $(`#quickReplyPresets option[value="${name}"]`).prop('selected', true); } saveSettingsDebounced(); } else { @@ -315,7 +322,7 @@ async function applyQuickReplyPreset(name) { addQuickReplyBar(); moduleWorker(); - $(`#quickReplyPresets option[value="${name}"]`).attr('selected', true); + $(`#quickReplyPresets option[value="${name}"]`).prop('selected', true); console.debug('QR Preset applied: ' + name); } @@ -340,7 +347,6 @@ async function doQR(_, text) { } jQuery(async () => { - moduleWorker(); setInterval(moduleWorker, UPDATE_INTERVAL); const settingsHtml = ` @@ -354,19 +360,19 @@ jQuery(async () => {