diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 4b75bd7..a89fb88 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -174,6 +174,16 @@ "settings_filters_target": { "message": "Injection Target" }, + "saving_current": { + "message": "Saving…" + }, + "saving_current_message": { + "message": "Leave your computer and this window open." + }, + "saving_done": { + "message": "Saved!" + }, + "JSON_parse_error": { "message": "There is a mistake in your JSON formatting. Please correct the error before saving." }, diff --git a/scripts/logging.js b/scripts/logging.js index 4dacc8d..3ca0bb4 100644 --- a/scripts/logging.js +++ b/scripts/logging.js @@ -14,7 +14,12 @@ export default class logging { return user_response; } - constructor(TITLE, MESSAGE) { + /* Create a new message. + + @param {string} TITLE the title + @param {string} MESSAGE the message + @param {bool} PRIORITY automatically dismiss other, older messages */ + constructor(TITLE, MESSAGE, PRIORITY = true) { // Set this message's properties. if (MESSAGE == null) { this.message = TITLE; @@ -23,6 +28,8 @@ export default class logging { this.message = MESSAGE; } + (PRIORITY) ? this.clear() : false; + // Display the message. console.log((MESSAGE ? (this.title).concat(`\n`) : ``).concat(this.message)); try { @@ -76,4 +83,15 @@ export default class logging { } catch (err) {}; }; } + + /* Clear the current message. */ + clear() { + try { + var toastElement = document.querySelectorAll('.toast'); + (toastElement) ? ( + toastElement.forEach((element) => { + element.style.display = "none"; + })) : false; + } catch(err) {}; + }; } diff --git a/scripts/secretariat.js b/scripts/secretariat.js index 7e84073..1b8e68f 100644 --- a/scripts/secretariat.js +++ b/scripts/secretariat.js @@ -3,6 +3,7 @@ Manage the local cache. */ import logging from "/scripts/logging.js"; +import texts from "/scripts/strings/read.js"; /* Read all stored data in the browser cache. @@ -207,6 +208,9 @@ export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = 0, OPTION export async function write(PATH, DATA, CLOUD = -1) { let DATA_INJECTED = {}; + // Inform the user that saving is in progress. + let notification = new logging ((new texts(`saving_current`)).localized, (new texts(`saving_current_message`)).localized, false); + /* Forcibly write the data to chrome database @param {object} DATA the data @@ -271,6 +275,9 @@ export async function write(PATH, DATA, CLOUD = -1) { // Write! write_database(DATA_INJECTED, CLOUD); + + // Inform the user that the saving operation is completed. + notification = new logging ((new texts(`saving_done`)).localized); } /* Dangerous: Resets all data or a domain's data.