From ae010478ba9b9b0b6673beb0a1ca88c40e64cb5a Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 6 Feb 2026 23:51:30 +0100 Subject: [PATCH] prompt copy button added. see #598 --- _locales/en/messages.json | 8 ++ pages/customprompts/mzta-custom-prompts.js | 94 ++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 87095fa4..6f9fa42a 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1852,5 +1852,13 @@ "prefs_OptionText_calendar_no_selection_Info": { "message": "If checked there is no need to select some text. The full message body will be used to get the calendar event.", "description": "" + }, + "customPrompts_btnCopy": { + "message": "Copy", + "description": "" + }, + "copy_text": { + "message": "copy", + "description": "" } } diff --git a/pages/customprompts/mzta-custom-prompts.js b/pages/customprompts/mzta-custom-prompts.js index 58bcbf04..55824f0d 100644 --- a/pages/customprompts/mzta-custom-prompts.js +++ b/pages/customprompts/mzta-custom-prompts.js @@ -324,6 +324,8 @@ document.addEventListener('DOMContentLoaded', async () => { let editBtn = document.querySelector(`tr[data-idnum="${curr_idnum}"] button.btnEditItem`); //console.log(`>>>>>>>>>>>> tr[data-idnum="${curr_idnum}"] button.btnEditItem`); editBtn.addEventListener('click', handleEditClick); + let copyBtn = document.querySelector(`tr[data-idnum="${curr_idnum}"] button.btnCopyItem`); + copyBtn.addEventListener('click', handleCopyClick); //console.log('>>>>>>>>>>>>> editBtn: ' + JSON.stringify(editBtn)); let deleteBtn = document.querySelector(`tr[data-idnum="${curr_idnum}"] button.btnDeleteItem`); //console.log(`>>>>>>>>>>>> tr[data-idnum="${curr_idnum}"] button.btnDeleteItem`); @@ -576,6 +578,7 @@ function handleEditClick(e) { tr.querySelector('.btnConfirmItem').style.display = 'inline'; // Save btn tr.querySelector('.btnCancelItem').style.display = 'inline'; // Cancel btn // tr.querySelector('.btnEditItem').style.display = 'none'; // Edit btn + tr.querySelector('.btnCopyItem').style.display = 'none'; // Copy btn tr.querySelector('.btnDeleteItem').style.display = 'none'; // Delete btn showItemRowEditor(tr); toggleDiffviewer(e); @@ -838,6 +841,7 @@ function handleCancelClick(e) { tr.querySelector('.btnConfirmItem').style.display = 'none'; // Save btn // tr.querySelector('.btnCancelItem').style.display = 'none'; // Cancel btn tr.querySelector('.btnEditItem').style.display = 'inline'; // Edit btn + tr.querySelector('.btnCopyItem').style.display = 'inline'; // Copy btn tr.querySelector('.btnDeleteItem').style.display = 'inline'; // Delete btn tr.querySelector('.id_output').value = tr.querySelector('.id_show').innerText.toLocaleUpperCase(); tr.querySelector('.name_output').value = tr.querySelector('.name_show').innerText; @@ -891,6 +895,7 @@ function handleConfirmClick(e) { // tr.querySelector('.btnConfirmItem').style.display = 'none'; // Ok btn tr.querySelector('.btnCancelItem').style.display = 'none'; // Cancel btn tr.querySelector('.btnEditItem').style.display = 'inline'; // Edit btn + tr.querySelector('.btnCopyItem').style.display = 'inline'; // Copy btn tr.querySelector('.btnDeleteItem').style.display = 'inline'; // Delete btn // Update item data tr.querySelector('.type').innerText = tr.querySelector('.type_output').value; @@ -942,6 +947,88 @@ function handleInputChange(e) { setSomethingChanged(); } +function handleCopyClick(e) { + e.preventDefault(); + const tr = e.target.parentNode.parentNode; + + let id = tr.querySelector('.id_output').value; + let name = tr.querySelector('.name_output').value; + let text = tr.querySelector('.text_output').value; + let type = tr.querySelector('.type_output').value; + let action = tr.querySelector('.action_output').value; + + let need_selected = tr.querySelector('.need_selected').checked; + let need_signature = tr.querySelector('.need_signature').checked; + let need_custom_text = tr.querySelector('.need_custom_text').checked; + let define_response_lang = tr.querySelector('.define_response_lang').checked; + let use_diff_viewer = tr.querySelector('.use_diff_viewer').checked; + + let chatgpt_web_model = tr.querySelector('.chatgpt_web_model_output').value; + let chatgpt_web_project = tr.querySelector('.chatgpt_web_project_output').value; + let chatgpt_web_custom_gpt = tr.querySelector('.chatgpt_web_custom_gpt_output').value; + + const item = promptsList.get('id', id.toLowerCase())[0]; + const itemValues = item.values(); + + // Populate new form + document.getElementById('txtIdNew').value = id + '_' + browser.i18n.getMessage("copy_text"); + document.getElementById('txtNameNew').value = name + ' (' + browser.i18n.getMessage("copy_text") + ')'; + document.getElementById('txtTextNew').value = text; + document.getElementById('selectTypeNew').value = type; + document.getElementById('selectActionNew').value = action; + + document.getElementById('checkboxNeedSelectedNew').checked = need_selected; + document.getElementById('checkboxNeedSignatureNew').checked = need_signature; + document.getElementById('checkboxNeedCustomTextNew').checked = need_custom_text; + document.getElementById('checkboxDefineResponseLangNew').checked = define_response_lang; + + let checkboxUseDiffViewerNew = document.getElementById('checkboxUseDiffViewerNew'); + checkboxUseDiffViewerNew.checked = use_diff_viewer; + checkboxUseDiffViewerNew.disabled = (action !== "2"); + + document.getElementById('chatGPTWebModelNew').value = chatgpt_web_model; + document.getElementById('chatGPTWebProjectNew').value = chatgpt_web_project; + document.getElementById('chatGPTWebCustomGPTNew').value = chatgpt_web_custom_gpt; + + const apiSelect = document.getElementById('new_prompt_api_type'); + if (apiSelect) { + apiSelect.value = itemValues.api_type || ''; + apiSelect.dispatchEvent(new Event('change')); + + for (const [integration, options] of Object.entries(integration_options_config)) { + for (const key of Object.keys(options)) { + const propName = `${integration}_${key}`; + const inputEl = document.getElementById(propName); + if (inputEl) { + let val = itemValues[propName]; + if (val === undefined) val = ''; + + if (inputEl.type === 'checkbox') { + inputEl.checked = (val === true || val === 'true'); + } else { + if (inputEl.tomselect) { + inputEl.tomselect.setValue(val, true); + setTomSelectBorder(inputEl.tomselect); + } else { + inputEl.value = val; + } + } + } + } + } + } + + // Show form + document.getElementById('formNew').style.display = 'block'; + + // Scroll to top + window.scrollTo({ + top: 0, + behavior: 'smooth' + }); + checkFields(); +} + //========= handling an item in a row - END @@ -1071,6 +1158,8 @@ function loadPromptsList(values){

+

+ `; //console.log('>>>>>>>> values.name: ' + JSON.stringify(values.name)); @@ -1111,6 +1200,11 @@ function loadPromptsList(values){ element.addEventListener('click', handleEditClick); }); + let btnCopyItem_elements = document.querySelectorAll(".btnCopyItem"); + btnCopyItem_elements.forEach(element => { + element.addEventListener('click', handleCopyClick); + }); + let btnDeleteItem_elements = document.querySelectorAll(".btnDeleteItem"); btnDeleteItem_elements.forEach(element => { element.addEventListener('click', handleDeleteClick);