diff --git a/e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/BaseTest.java b/e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/BaseTest.java index cf0edad..00cc48c 100644 --- a/e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/BaseTest.java +++ b/e2e/src/test/java/org/yorkxin/copyasmarkdown/e2e/BaseTest.java @@ -252,7 +252,7 @@ protected void openOptionsPermissionsPage() { } protected void openCustomFormatPage(String slot) { - driver.get(getExtensionProtocol()+"://"+extId+"/dist/ui/custom-format.html?slot="+slot); + driver.get(getExtensionProtocol()+"://"+extId+"/dist/ui/export-tabs-custom-format.html?slot="+slot); } protected String getExtensionProtocol() { diff --git a/src/background.js b/src/background.js index 1546437..b5a5eb7 100644 --- a/src/background.js +++ b/src/background.js @@ -229,7 +229,7 @@ function renderBuiltInFormat(format, tabLists, listType) { * @returns {string} */ async function renderCustomFormat({ slot, lists }) { - const customFormat = await CustomFormatsStorage.get(slot); + const customFormat = await CustomFormatsStorage.get('tabs', slot); const input = CustomFormat.makeRenderInput(lists); return customFormat.render(input); } diff --git a/src/lib/custom-format.js b/src/lib/custom-format.js index 3f5bc96..0a7fe16 100644 --- a/src/lib/custom-format.js +++ b/src/lib/custom-format.js @@ -5,6 +5,8 @@ Mustache.escape = function (text) { return text; }; /** @typedef {import('./tabs.js').TabList} TabList */ +/** @typedef {'tabs'} Context */ + /** * @typedef {Object} RenderInputLink * @prop {String} title @@ -29,17 +31,20 @@ Mustache.escape = function (text) { return text; }; export default class CustomFormat { /** * @param {Object} params + * @param {Context} context * @param {string} params.slot * @param {string} params.name * @param {string} params.template * @param {boolean} params.showInPopupMenu */ constructor({ + context, slot, name, template, showInPopupMenu, }) { + this.context = context; this.slot = slot; this.name = name; this.template = template; @@ -100,4 +105,4 @@ export default class CustomFormat { return { links, groups }; } -} \ No newline at end of file +} diff --git a/src/storage/custom-formats-storage.js b/src/storage/custom-formats-storage.js index 5c6d9b0..29e1c41 100644 --- a/src/storage/custom-formats-storage.js +++ b/src/storage/custom-formats-storage.js @@ -1,27 +1,28 @@ import CustomFormat from '../lib/custom-format.js'; -function storageKeyOf(slot, attribute) { - return `custom_formats.${slot}.${attribute}`; +function storageKeyOf(context, slot, attribute) { + return `custom_formats.${context}.${slot}.${attribute}`; } export default { /** * + * @param context {string} * @param slot {string} * @returns {Promise} */ - async get(slot) { + async get(context, slot) { const stored = await browser.storage.sync.get({ - [storageKeyOf(slot, 'name')]: '', - [storageKeyOf(slot, 'template')]: '', - [storageKeyOf(slot, 'show_in_popup_menu')]: false, + [storageKeyOf(context, slot, 'name')]: '', + [storageKeyOf(context, slot, 'template')]: '', + [storageKeyOf(context, slot, 'show_in_popup_menu')]: false, }); return new CustomFormat({ slot, - name: stored[storageKeyOf(slot, 'name')], - template: stored[storageKeyOf(slot, 'template')], - showInPopupMenu: stored[storageKeyOf(slot, 'show_in_popup_menu')], + name: stored[storageKeyOf(context, slot, 'name')], + template: stored[storageKeyOf(context, slot, 'template')], + showInPopupMenu: stored[storageKeyOf(context, slot, 'show_in_popup_menu')], }); }, @@ -29,21 +30,22 @@ export default { * * @returns {Promise} */ - async list() { - return Promise.all(['1', '2', '3', '4', '5'].map((slot) => this.get(slot))); + async list(context) { + return Promise.all(['1', '2', '3', '4', '5'].map((slot) => this.get(context, slot))); }, /** * + * @param context {string} * @param slot {string} * @param customFormat {CustomFormat} * @returns {Promise} */ - async save(slot, customFormat) { + async save(context, slot, customFormat) { const assignments = { - [storageKeyOf(slot, 'name')]: customFormat.name, - [storageKeyOf(slot, 'template')]: customFormat.template, - [storageKeyOf(slot, 'show_in_popup_menu')]: customFormat.showInPopupMenu, + [storageKeyOf(context, slot, 'name')]: customFormat.name, + [storageKeyOf(context, slot, 'template')]: customFormat.template, + [storageKeyOf(context, slot, 'show_in_popup_menu')]: customFormat.showInPopupMenu, }; await browser.storage.sync.set(assignments); diff --git a/src/ui/about.html b/src/ui/about.html index 93441ac..86c2fa7 100644 --- a/src/ui/about.html +++ b/src/ui/about.html @@ -22,11 +22,11 @@

Copy as Markdown

diff --git a/src/ui/custom-format-help.html b/src/ui/custom-format-help.html index 2e5e289..5b09fd3 100644 --- a/src/ui/custom-format-help.html +++ b/src/ui/custom-format-help.html @@ -22,11 +22,11 @@

Copy as Markdown

diff --git a/src/ui/custom-format.js b/src/ui/custom-format.js index fa897f6..7e85b08 100644 --- a/src/ui/custom-format.js +++ b/src/ui/custom-format.js @@ -105,8 +105,12 @@ class UI { number: 1, ol: 1, links: [ - { title: 'Example 1', url: 'https://example.com/1', number: 1, ol: 1 }, - { title: 'Example 2', url: 'https://example.com/2', number: 2, ol: 2 }, + { + title: 'Example 1', url: 'https://example.com/1', number: 1, ol: 1, + }, + { + title: 'Example 2', url: 'https://example.com/2', number: 2, ol: 2, + }, ], }, { @@ -115,8 +119,12 @@ class UI { number: 2, ol: 3, links: [ - { title: 'Example 3', url: 'https://example.com/3', number: 1, ol: 1 }, - { title: 'Example 4', url: 'https://example.com/4', number: 2, ol: 2 }, + { + title: 'Example 3', url: 'https://example.com/3', number: 1, ol: 1, + }, + { + title: 'Example 4', url: 'https://example.com/4', number: 2, ol: 2, + }, ], }, { @@ -125,8 +133,12 @@ class UI { number: 3, ol: 4, links: [ - { title: 'Example 5', url: 'https://example.com/5', number: 1, ol: 4 }, - { title: 'Example 6', url: 'https://example.com/6', number: 2, ol: 5 }, + { + title: 'Example 5', url: 'https://example.com/5', number: 1, ol: 4, + }, + { + title: 'Example 6', url: 'https://example.com/6', number: 2, ol: 5, + }, ], }, ], @@ -136,10 +148,10 @@ class UI { document.addEventListener('DOMContentLoaded', async () => { const ui = new UI(document); - const customFormat = await CustomFormatsStorage.get(ui.slot); + const customFormat = await CustomFormatsStorage.get('tabs', ui.slot); ui.load(customFormat); ui.elSave.addEventListener('click', async () => { - await CustomFormatsStorage.save(ui.slot, ui.current()); + await CustomFormatsStorage.save('tabs', ui.slot, ui.current()); }); }); diff --git a/src/ui/custom-format.html b/src/ui/export-tabs-custom-format.html similarity index 80% rename from src/ui/custom-format.html rename to src/ui/export-tabs-custom-format.html index c588732..e0828ac 100644 --- a/src/ui/custom-format.html +++ b/src/ui/export-tabs-custom-format.html @@ -18,13 +18,13 @@

Copy as Markdown

  • Markdown Style
  • Permissions
  • - + diff --git a/src/ui/options-permissions.html b/src/ui/options-permissions.html index e5a76d1..e418c30 100644 --- a/src/ui/options-permissions.html +++ b/src/ui/options-permissions.html @@ -22,11 +22,11 @@

    Copy as Markdown - Additional Permissions

    diff --git a/src/ui/options.html b/src/ui/options.html index 6aa20c2..7301813 100644 --- a/src/ui/options.html +++ b/src/ui/options.html @@ -20,13 +20,13 @@

    Copy as Markdown

  • Markdown Style
  • Permissions
  • - + diff --git a/src/ui/popup.js b/src/ui/popup.js index 28f1322..636ea59 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -120,7 +120,7 @@ async function showCustomFormats() { const divExportAll = document.getElementById('actions-export-all'); const divExportHighlighted = document.getElementById('actions-export-highlighted'); - const customFormats = await CustomFormatsStorage.list(); + const customFormats = await CustomFormatsStorage.list('tabs'); customFormats.forEach((customFormat) => { if (!customFormat.showInPopupMenu) { return;