From 3de3d3869e3e5d25101a64122aad15c7c4b9590f Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sat, 27 Apr 2019 10:18:23 +0200 Subject: [PATCH] Add actions on dump There are options to configure weither or not you want the dump entries sorted and/or unique. These are disabled by default. --- _locales/en/messages.json | 10 +++++++++- _locales/fr/messages.json | 10 +++++++++- background.js | 17 +++++++++++++++-- options/options.css | 10 ++++++---- options/options.html | 12 ++++++++++-- options/options.js | 2 ++ popup/load.content.js | 2 +- 7 files changed, 52 insertions(+), 11 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 41010bf..c2d4f94 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -20,9 +20,17 @@ "description": "Notify the user that the storage has been copied to the clipboard." }, "optionsClearAfter": { - "message": "Clear dump after:", + "message": "Clear dump after", "description": "Label for the option to select if the dump is cleared after an action on it." }, + "optionsSortDump": { + "message": "Sort entries", + "description": "Label for the option to select if dump entries are sorted." + }, + "optionsUniqueDump": { + "message": "Remove duplicate entries", + "description": "Label for the option to select if dump entries are unique." + }, "popupButtonActionClear": { "message": "Clear dump", "description": "Label for the clear dump button" diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 7d8c107..85419a8 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -20,9 +20,17 @@ "description": "Notify the user that the storage has been copied to the clipboard." }, "optionsClearAfter": { - "message": "Nettoyer l'entrepôt après :", + "message": "Nettoyer l'entrepôt après", "description": "Label for the option to select if the dump is cleared after an action on it." }, + "optionsSortDump": { + "message": "Trier les liens", + "description": "Label for the option to select if dump entries are sorted." + }, + "optionsUniqueDump": { + "message": "Supprimer les doublons", + "description": "Label for the option to select if dump entries are unique." + }, "popupButtonActionClear": { "message": "Nettoyer l'entrepôt", "description": "Label for the clear dump button" diff --git a/background.js b/background.js index b3b709f..aca3aad 100644 --- a/background.js +++ b/background.js @@ -18,9 +18,22 @@ function notification(message) { } async function addLink(link) { - const obj = await browser.storage.local.get('urls'); - const urls = obj.urls || []; + const storage = await browser.storage.local.get('urls'); + let urls = storage.urls || []; urls.push(link); + + await browser.storage.local.get('options').then(obj => { + if (obj.options === undefined || obj.options.other === undefined) { + return; + } + if (obj.options.other.sort) { + urls.sort((a, b) => a.title.localeCompare(b.title)); + } + if (obj.options.other.unique) { + urls = urls.filter((item, index, self) => self.findIndex(t => t.url === item.url) === index); + } + }) + await browser.storage.local.set({ "urls": urls.flat() }); } diff --git a/options/options.css b/options/options.css index 2b4cb0e..fa86ca8 100644 --- a/options/options.css +++ b/options/options.css @@ -16,12 +16,14 @@ table { width: 100%; border-collapse: collapse; } -thead th { - border-bottom: 1px solid var(--inactive-color); -} -tfoot td { +tbody tr:first-child th, +tbody tr:first-child td, +tbody tr:last-child td { border-top: 1px solid var(--inactive-color); } +tfoot tr:first-child td { + padding-top: 50px; +} th, td { text-align: left; padding: 5px 0; diff --git a/options/options.html b/options/options.html index 111fba0..743d166 100644 --- a/options/options.html +++ b/options/options.html @@ -41,13 +41,21 @@ - - + + + + + + + + + + diff --git a/options/options.js b/options/options.js index 01ec7d6..c235d0d 100644 --- a/options/options.js +++ b/options/options.js @@ -29,3 +29,5 @@ browser.storage.local.get('options').then(obj => { document.querySelector('[for="downloadAction"]').textContent = browser.i18n.getMessage(`popupButtonActionDownload`); document.querySelector('[for="copyAction"]').textContent = browser.i18n.getMessage(`popupButtonActionCopy`); document.querySelector('[for="clearAfter"]').textContent = browser.i18n.getMessage(`optionsClearAfter`); +document.querySelector('[for="sortDump"]').textContent = browser.i18n.getMessage(`optionsSortDump`); +document.querySelector('[for="uniqueDump"]').textContent = browser.i18n.getMessage(`optionsUniqueDump`); diff --git a/popup/load.content.js b/popup/load.content.js index 7e180da..5239f3c 100644 --- a/popup/load.content.js +++ b/popup/load.content.js @@ -32,7 +32,7 @@ function drawHiddenContent() { browser.storage.local.get('options').then(obj => { if (obj.options !== undefined) { Object.entries(obj.options).forEach(([action, formats]) => { - if (action === 'clear') { + if (action !== 'download' && action !== 'copy') { return; } Object.entries(formats).forEach(([format, value]) => {