Skip to content

Commit

Permalink
Add actions on dump
Browse files Browse the repository at this point in the history
There are options to configure weither or not you want the dump entries sorted
and/or unique. These are disabled by default.
  • Loading branch information
aledeg committed Apr 27, 2019
1 parent f0ae3af commit 3de3d38
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
10 changes: 9 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 15 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
}

Expand Down
10 changes: 6 additions & 4 deletions options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@
<td><label class="switch"><input type="checkbox" checked="checked" data-action="download" data-format="phpbb"><span class="slider"></span></label></td>
<td><label class="switch"><input type="checkbox" checked="checked" data-action="copy" data-format="phpbb"><span class="slider"></span></label></td>
</tr>
</tbody>
<tfoot>
<tr>
<td><label for="clearAfter">Clear dump after</label></td>
<td><label class="switch"><input type="checkbox" data-action="clear" data-format="download"><span class="slider"></span></label></td>
<td><label class="switch"><input type="checkbox" data-action="clear" data-format="copy"><span class="slider"></span></label></td>
</tr>
</tbody>
<tfoot>
<tr>
<td><label for="sortDump">Sort dump</label></td>
<td colspan="2"><label class="switch"><input type="checkbox" data-action="other" data-format="sort"><span class="slider"></span></label></td>
</tr>
<tr>
<td><label for="uniqueDump">Remove duplicate</label></td>
<td colspan="2"><label class="switch"><input type="checkbox" data-action="other" data-format="unique"><span class="slider"></span></label></td>
</tr>
</tfoot>
</table>
</form>
Expand Down
2 changes: 2 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
2 changes: 1 addition & 1 deletion popup/load.content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down

0 comments on commit 3de3d38

Please sign in to comment.