Revision 5c685518
Added by koszko about 2 years ago
background/storage_server.js | ||
---|---|---|
9 | 9 |
* IMPORTS_START |
10 | 10 |
* IMPORT listen_for_connection |
11 | 11 |
* IMPORT get_storage |
12 |
* IMPORT TYPE_PREFIX
|
|
12 |
* IMPORT list_prefixes
|
|
13 | 13 |
* IMPORT CONNECTION_TYPE |
14 | 14 |
* IMPORTS_END |
15 | 15 |
*/ |
... | ... | |
38 | 38 |
{ |
39 | 39 |
console.log("new remote storage connection!"); |
40 | 40 |
|
41 |
port.postMessage({
|
|
42 |
[TYPE_PREFIX.SCRIPT] : storage.get_all(TYPE_PREFIX.SCRIPT),
|
|
43 |
[TYPE_PREFIX.BAG] : storage.get_all(TYPE_PREFIX.BAG),
|
|
44 |
[TYPE_PREFIX.PAGE] : storage.get_all(TYPE_PREFIX.PAGE) |
|
45 |
});
|
|
41 |
const message = {};
|
|
42 |
for (const prefix of list_prefixes)
|
|
43 |
message[prefix] = storage.get_all(prefix);
|
|
44 |
|
|
45 |
port.postMessage(message);
|
|
46 | 46 |
|
47 | 47 |
let handle_change = change => port.postMessage(change); |
48 | 48 |
|
common/storage_client.js | ||
---|---|---|
8 | 8 |
/* |
9 | 9 |
* IMPORTS_START |
10 | 10 |
* IMPORT CONNECTION_TYPE |
11 |
* IMPORT TYPE_PREFIX |
|
12 | 11 |
* IMPORT list_prefixes |
13 | 12 |
* IMPORT make_once |
14 | 13 |
* IMPORT browser |
... | ... | |
47 | 46 |
setTimeout(resolve, 0, message.result); |
48 | 47 |
} |
49 | 48 |
|
50 |
function list(name, prefix) |
|
51 |
{ |
|
52 |
return {prefix, name, listeners : new Set()}; |
|
53 |
} |
|
54 |
|
|
55 |
var scripts = list("scripts", TYPE_PREFIX.SCRIPT); |
|
56 |
var bags = list("bags", TYPE_PREFIX.BAG); |
|
57 |
var pages = list("pages", TYPE_PREFIX.PAGE); |
|
49 |
const list_by_prefix = {}; |
|
58 | 50 |
|
59 |
const list_by_prefix = { |
|
60 |
[TYPE_PREFIX.SCRIPT] : scripts, |
|
61 |
[TYPE_PREFIX.BAG] : bags, |
|
62 |
[TYPE_PREFIX.PAGE] : pages |
|
63 |
}; |
|
51 |
for (const prefix of list_prefixes) |
|
52 |
list_by_prefix[prefix] = {prefix, listeners : new Set()}; |
|
64 | 53 |
|
65 | 54 |
var resolve_init; |
66 | 55 |
|
common/stored_types.js | ||
---|---|---|
14 | 14 |
*/ |
15 | 15 |
|
16 | 16 |
const TYPE_PREFIX = { |
17 |
REPO: "r", |
|
17 | 18 |
PAGE : "p", |
18 | 19 |
BAG : "b", |
19 | 20 |
SCRIPT : "s", |
... | ... | |
21 | 22 |
}; |
22 | 23 |
|
23 | 24 |
const TYPE_NAME = { |
25 |
[TYPE_PREFIX.REPO] : "repo", |
|
24 | 26 |
[TYPE_PREFIX.PAGE] : "page", |
25 | 27 |
[TYPE_PREFIX.BAG] : "bag", |
26 | 28 |
[TYPE_PREFIX.SCRIPT] : "script" |
27 | 29 |
} |
28 | 30 |
|
29 | 31 |
const list_prefixes = [ |
32 |
TYPE_PREFIX.REPO, |
|
30 | 33 |
TYPE_PREFIX.PAGE, |
31 | 34 |
TYPE_PREFIX.BAG, |
32 | 35 |
TYPE_PREFIX.SCRIPT |
html/options.html | ||
---|---|---|
33 | 33 |
} |
34 | 34 |
|
35 | 35 |
/* tabbed view */ |
36 |
#show_repos:not(:checked) ~ #repos, |
|
36 | 37 |
#show_pages:not(:checked) ~ #pages, |
37 | 38 |
#show_bags:not(:checked) ~ #bags, |
38 | 39 |
#show_scripts:not(:checked) ~ #scripts { |
39 | 40 |
display: none; |
40 | 41 |
} |
41 | 42 |
|
43 |
#show_repos:checked ~ #repos_lbl, |
|
42 | 44 |
#show_pages:checked ~ #pages_lbl, |
43 | 45 |
#show_bags:checked ~ #bags_lbl, |
44 | 46 |
#show_scripts:checked ~ #scripts_lbl { |
... | ... | |
124 | 126 |
</div> |
125 | 127 |
|
126 | 128 |
<!-- Mind the show_*s ids below - their format is assumed in js code --> |
129 |
<input type="radio" name="tabs" id="show_repos"></input> |
|
127 | 130 |
<input type="radio" name="tabs" id="show_pages" checked></input> |
128 | 131 |
<input type="radio" name="tabs" id="show_bags"></input> |
129 | 132 |
<input type="radio" name="tabs" id="show_scripts"></input> |
133 |
<label for="show_repos" id="repos_lbl" |
|
134 |
class="tab_head"> Repos </label> |
|
130 | 135 |
<label for="show_pages" id="pages_lbl" |
131 | 136 |
class="tab_head"> Pages </label> |
132 | 137 |
<label for="show_bags" id="bags_lbl" |
... | ... | |
134 | 139 |
<label for="show_scripts" id="scripts_lbl" |
135 | 140 |
class="tab_head"> Scripts </label> |
136 | 141 |
|
142 |
<div id="repos"> |
|
143 |
<ul id="repos_ul"> |
|
144 |
<li id="work_repo_li" class="hide"> |
|
145 |
<label for="repo_url_field">URL: </label> |
|
146 |
<input id="repo_url_field"></input> |
|
147 |
<br/> |
|
148 |
<button id="save_repo_but" type="button"> Save </button> |
|
149 |
<button id="discard_repo_but" type="button"> Cancel </button> |
|
150 |
</li> |
|
151 |
</ul> |
|
152 |
<button id="add_repo_but" type="button"> Add repository </button> |
|
153 |
</div> |
|
154 |
|
|
137 | 155 |
<div id="pages"> |
138 | 156 |
<ul id="pages_ul"> |
139 | 157 |
<li id="work_page_li" class="hide"> |
html/options_main.js | ||
---|---|---|
38 | 38 |
return `li_${prefix}_${item}`; |
39 | 39 |
} |
40 | 40 |
|
41 |
/* Insert into list of bags/pages/scripts */ |
|
41 |
/* Insert into list of bags/pages/scripts/repos */
|
|
42 | 42 |
function add_li(prefix, item, at_the_end=false) |
43 | 43 |
{ |
44 | 44 |
let ul = ul_by_prefix[prefix]; |
... | ... | |
58 | 58 |
let export_button = remove_button.nextElementSibling; |
59 | 59 |
export_button.addEventListener("click", |
60 | 60 |
() => export_item(prefix, item)); |
61 |
if (prefix === TYPE_PREFIX.REPO) |
|
62 |
export_button.remove(); |
|
61 | 63 |
|
62 | 64 |
if (!at_the_end) { |
63 | 65 |
for (let element of ul.ul.children) { |
... | ... | |
89 | 91 |
|
90 | 92 |
function add_chbx_li(prefix, name) |
91 | 93 |
{ |
92 |
if (prefix === TYPE_PREFIX.PAGE)
|
|
94 |
if (![TYPE_PREFIX.BAG, TYPE_PREFIX.SCRIPT].includes(prefix))
|
|
93 | 95 |
return; |
94 | 96 |
|
95 | 97 |
let li = chbx_component_li_template.cloneNode(true); |
... | ... | |
109 | 111 |
|
110 | 112 |
function add_radio_li(prefix, name) |
111 | 113 |
{ |
112 |
if (prefix === TYPE_PREFIX.PAGE)
|
|
114 |
if (![TYPE_PREFIX.BAG, TYPE_PREFIX.SCRIPT].includes(prefix))
|
|
113 | 115 |
return; |
114 | 116 |
|
115 | 117 |
let li = radio_component_li_template.cloneNode(true); |
... | ... | |
125 | 127 |
radio_components_ul.insertBefore(li, radio_component_none_li); |
126 | 128 |
} |
127 | 129 |
|
130 |
/* Used to reset edited repo. */ |
|
131 |
function reset_work_repo_li(ul, item, _) |
|
132 |
{ |
|
133 |
ul.work_name_input.value = maybe_string(item); |
|
134 |
} |
|
135 |
|
|
136 |
/* Used to get repo data for saving */ |
|
137 |
function work_repo_li_data(ul) |
|
138 |
{ |
|
139 |
return [ul.work_name_input.value, {}]; |
|
140 |
} |
|
141 |
|
|
128 | 142 |
const page_payload_span = by_id("page_payload"); |
129 | 143 |
|
130 | 144 |
function set_page_components(components) |
... | ... | |
461 | 475 |
}; |
462 | 476 |
|
463 | 477 |
const ul_by_prefix = { |
478 |
[TYPE_PREFIX.REPO] : { |
|
479 |
ul : by_id("repos_ul"), |
|
480 |
work_li : by_id("work_repo_li"), |
|
481 |
work_name_input : by_id("repo_url_field"), |
|
482 |
reset_work_li : reset_work_repo_li, |
|
483 |
get_work_li_data : work_repo_li_data, |
|
484 |
state : UL_STATE.IDLE, |
|
485 |
edited_item : undefined, |
|
486 |
}, |
|
464 | 487 |
[TYPE_PREFIX.PAGE] : { |
465 | 488 |
ul : by_id("pages_ul"), |
466 | 489 |
work_li : by_id("work_page_li"), |
... | ... | |
727 | 750 |
discard_but.addEventListener("click", () => cancel_work(prefix)); |
728 | 751 |
save_but.addEventListener("click", () => save_work(prefix)); |
729 | 752 |
|
730 |
if (prefix === TYPE_PREFIX.SCRIPT)
|
|
753 |
if ([TYPE_PREFIX.REPO, TYPE_PREFIX.SCRIPT].includes(prefix))
|
|
731 | 754 |
continue; |
732 | 755 |
|
733 | 756 |
let ul = ul_by_prefix[prefix]; |
... | ... | |
772 | 795 |
|
773 | 796 |
let uls_creators = [[ul.ul, item_li_id]]; |
774 | 797 |
|
775 |
if (change.prefix !== TYPE_PREFIX.PAGE) {
|
|
798 |
if ([TYPE_PREFIX.BAG, TYPE_PREFIX.SCRIPT].includes(change.prefix)) {
|
|
776 | 799 |
uls_creators.push([chbx_components_ul, chbx_li_id]); |
777 | 800 |
uls_creators.push([radio_components_ul, radio_li_id]); |
778 | 801 |
} |
Also available in: Unified diff
store repository URLs in settings