From 5c68551800e477db41ae6fe3a318b2ff2d7a9cb1 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 21 Jul 2021 17:42:21 +0200 Subject: store repository URLs in settings --- background/storage_server.js | 12 ++++++------ common/storage_client.js | 17 +++-------------- common/stored_types.js | 3 +++ html/options.html | 18 ++++++++++++++++++ html/options_main.js | 33 ++++++++++++++++++++++++++++----- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/background/storage_server.js b/background/storage_server.js index 554aff2..2252eb5 100644 --- a/background/storage_server.js +++ b/background/storage_server.js @@ -9,7 +9,7 @@ * IMPORTS_START * IMPORT listen_for_connection * IMPORT get_storage - * IMPORT TYPE_PREFIX + * IMPORT list_prefixes * IMPORT CONNECTION_TYPE * IMPORTS_END */ @@ -38,11 +38,11 @@ function new_connection(port) { console.log("new remote storage connection!"); - port.postMessage({ - [TYPE_PREFIX.SCRIPT] : storage.get_all(TYPE_PREFIX.SCRIPT), - [TYPE_PREFIX.BAG] : storage.get_all(TYPE_PREFIX.BAG), - [TYPE_PREFIX.PAGE] : storage.get_all(TYPE_PREFIX.PAGE) - }); + const message = {}; + for (const prefix of list_prefixes) + message[prefix] = storage.get_all(prefix); + + port.postMessage(message); let handle_change = change => port.postMessage(change); diff --git a/common/storage_client.js b/common/storage_client.js index 4849a65..2b2f495 100644 --- a/common/storage_client.js +++ b/common/storage_client.js @@ -8,7 +8,6 @@ /* * IMPORTS_START * IMPORT CONNECTION_TYPE - * IMPORT TYPE_PREFIX * IMPORT list_prefixes * IMPORT make_once * IMPORT browser @@ -47,20 +46,10 @@ function handle_message(message) setTimeout(resolve, 0, message.result); } -function list(name, prefix) -{ - return {prefix, name, listeners : new Set()}; -} - -var scripts = list("scripts", TYPE_PREFIX.SCRIPT); -var bags = list("bags", TYPE_PREFIX.BAG); -var pages = list("pages", TYPE_PREFIX.PAGE); +const list_by_prefix = {}; -const list_by_prefix = { - [TYPE_PREFIX.SCRIPT] : scripts, - [TYPE_PREFIX.BAG] : bags, - [TYPE_PREFIX.PAGE] : pages -}; +for (const prefix of list_prefixes) + list_by_prefix[prefix] = {prefix, listeners : new Set()}; var resolve_init; diff --git a/common/stored_types.js b/common/stored_types.js index a6f1f2f..304842b 100644 --- a/common/stored_types.js +++ b/common/stored_types.js @@ -14,6 +14,7 @@ */ const TYPE_PREFIX = { + REPO: "r", PAGE : "p", BAG : "b", SCRIPT : "s", @@ -21,12 +22,14 @@ const TYPE_PREFIX = { }; const TYPE_NAME = { + [TYPE_PREFIX.REPO] : "repo", [TYPE_PREFIX.PAGE] : "page", [TYPE_PREFIX.BAG] : "bag", [TYPE_PREFIX.SCRIPT] : "script" } const list_prefixes = [ + TYPE_PREFIX.REPO, TYPE_PREFIX.PAGE, TYPE_PREFIX.BAG, TYPE_PREFIX.SCRIPT diff --git a/html/options.html b/html/options.html index bfb9e52..a10b919 100644 --- a/html/options.html +++ b/html/options.html @@ -33,12 +33,14 @@ } /* tabbed view */ + #show_repos:not(:checked) ~ #repos, #show_pages:not(:checked) ~ #pages, #show_bags:not(:checked) ~ #bags, #show_scripts:not(:checked) ~ #scripts { display: none; } + #show_repos:checked ~ #repos_lbl, #show_pages:checked ~ #pages_lbl, #show_bags:checked ~ #bags_lbl, #show_scripts:checked ~ #scripts_lbl { @@ -124,9 +126,12 @@ + + +
+ + +
+