From 5b44e3147e32aec1efae8158a4911442beb8a6d1 Mon Sep 17 00:00:00 2001 From: mic Date: Mon, 13 May 2024 23:13:00 +0200 Subject: [PATCH] messages in saving procedure added. related to #12 --- _locales/en/messages.json | 35 ++++++++++++++++++++++++++++ customprompts/mzta-custom-prompts.js | 26 +++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e180fc9a..424b6a9d 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -59,6 +59,41 @@ "description": "" }, + "customPrompts_start_saving": { + "message": "Saving prompts...", + "description": "" + }, + + "customPrompts_reindexing_list": { + "message": "Reindexing list...", + "description": "" + }, + + "customPrompts_filtering_prompts": { + "message": "Filtering prompts...", + "description": "" + }, + + "customPrompts_saving_default_prompts": { + "message": "Saving default prompts...", + "description": "" + }, + + "customPrompts_saving_custom_prompts": { + "message": "Saving custom prompts...", + "description": "" + }, + + "customPrompts_reloading_menus": { + "message": "Reloading menus...", + "description": "" + }, + + "customPrompts_saved": { + "message": "Prompts saved!", + "description": "" + }, + "customPrompts_managePrompts_statement": { "message": "Manage your custom prompts.", "description": "" diff --git a/customprompts/mzta-custom-prompts.js b/customprompts/mzta-custom-prompts.js index 00bfd252..60f90cfd 100644 --- a/customprompts/mzta-custom-prompts.js +++ b/customprompts/mzta-custom-prompts.js @@ -23,6 +23,7 @@ var somethingChanged = false; var positionMax_compose = 0; var positionMax_display = 0; var idnumMax = 0; +var msgTimeout = null; document.addEventListener('DOMContentLoaded', async () => { let options = { @@ -421,6 +422,7 @@ function inputClearError(input) { } function setSomethingChanged(){ + clearTimeout(msgTimeout); somethingChanged = true; document.getElementById('btnSaveAll').disabled = false; let msgDisplay = document.getElementById('msgDisplay'); @@ -463,8 +465,10 @@ function checkSelectedBoxes(checkboxes = null) { //Save all prompts async function saveAll() { + setMessage(browser.i18n.getMessage('customPrompts_start_saving')); setNothingChanged(); if(promptsList != null) { + setMessage(browser.i18n.getMessage('customPrompts_reindexing_list')); promptsList.reIndex(); let newPrompts = promptsList.items.map(item => { // For each item in the array, return only the '_values' part @@ -474,15 +478,37 @@ async function saveAll() { // console.log('>>>>>>>>>>>>> id: ' + JSON.stringify(prompt)); // }); //console.log('>>>>>>>>>>>>> saveAll: ' + JSON.stringify(newPrompts)); + setMessage(browser.i18n.getMessage('customPrompts_filtering_prompts')); let newDefaultPrompts = newPrompts.filter(item => item.is_default == 1); //console.log('>>>>>>>>>>>>> newDefaultPrompts: ' + JSON.stringify(newDefaultPrompts)); let newCustomPrompts = newPrompts.filter(item => item.is_default == 0); + setMessage(browser.i18n.getMessage('customPrompts_saving_default_prompts')); await setDefaultPromptsProperties(newDefaultPrompts); + setMessage(browser.i18n.getMessage('customPrompts_saving_custom_prompts')); await setCustomPrompts(newCustomPrompts); + setMessage(browser.i18n.getMessage('customPrompts_reloading_menus')); browser.runtime.sendMessage({command: "reload_menus"}); + setMessage(browser.i18n.getMessage('customPrompts_saved'),'green'); + msgTimeout = setTimeout(() => { + clearMessage(); + }, 10000) } } +function setMessage(msg, color = '') { + clearTimeout(msgTimeout); + let msgDisplay = document.getElementById('msgDisplay'); + msgDisplay.innerHTML = msg; + msgDisplay.style.display = 'inline'; + msgDisplay.style.color = color; +} + +function clearMessage() { + let msgDisplay = document.getElementById('msgDisplay'); + msgDisplay.innerHTML = ''; + msgDisplay.style.display = 'none'; + msgDisplay.style.color = ''; +} // window.addEventListener('beforeunload', function (event) {