Skip to content

Commit

Permalink
fix: options not restored/saved
Browse files Browse the repository at this point in the history
  • Loading branch information
igorlogius committed Apr 2, 2024
1 parent 8242898 commit df3bab1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ async function buildRegExList() {

async function getFromStorage(type, id, fallback) {
let tmp = await browser.storage.local.get(id);
return typeof tmp[id] === type ? tmp[id] : fallback;
if (typeof tmp[id] === type) {
return tmp[id];
}
await setToStorage(id, fallback);
return fallback;
}

async function setToStorage(id, value) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"tabs"
],
"optional_permissions": ["bookmarks", "history"],
"version": "1.1.30"
"version": "1.1.31"
}
16 changes: 8 additions & 8 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ <h4>
<abbr title="Hold CTRL to select or deselect multiple colors">(?)</abbr>
</h4>
<select id="usecolors" multiple style="min-height: 13em; width: 100%">
<option value="blue" selected>blue</option>
<option value="turquoise" selected>turquoise</option>
<option value="green" selected>green</option>
<option value="yellow" selected>yellow</option>
<option value="orange" selected>orange</option>
<option value="red" selected>red</option>
<option value="pink" selected>pink</option>
<option value="purple" selected>purple</option>
<option value="blue">blue</option>
<option value="turquoise">turquoise</option>
<option value="green">green</option>
<option value="yellow">yellow</option>
<option value="orange">orange</option>
<option value="red">red</option>
<option value="pink">pink</option>
<option value="purple">purple</option>
</select>
</fieldset>

Expand Down
6 changes: 4 additions & 2 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ function onChange(evt) {
let el = document.getElementById(id);
let val = obj[id];

if (Array.isArray(val) && val.length > 0) {
for (var i = 0; i < el.options.length; i++) {
for (var i = 0; i < el.options.length; i++) {
if (Array.isArray(val)) {
el.options[i].selected = val.includes(el.options[i].value);
} else {
el.options[i].selected = val == el.options[i].value;
}
}
})
Expand Down

0 comments on commit df3bab1

Please sign in to comment.