Skip to content

Commit

Permalink
Use async/await in options.js (#457)
Browse files Browse the repository at this point in the history
Co-authored-by: rebloor <[email protected]>
  • Loading branch information
Flimm and rebloor authored Sep 5, 2023
1 parent a468a4c commit 6392240
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions favourite-colour/options.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
function saveOptions(e) {
browser.storage.sync.set({
async function saveOptions(e) {
e.preventDefault();
await browser.storage.sync.set({
colour: document.querySelector("#colour").value
});
e.preventDefault();
}

function restoreOptions() {
let storageItem = browser.storage.managed.get('colour');
storageItem.then((res) => {
document.querySelector("#managed-colour").innerText = res.colour;
});
async function restoreOptions() {
let res = await browser.storage.managed.get('colour');
document.querySelector("#managed-colour").innerText = res.colour;

let gettingItem = browser.storage.sync.get('colour');
gettingItem.then((res) => {
document.querySelector("#colour").value = res.colour || 'Firefox red';
});
res = await browser.storage.sync.get('colour');
document.querySelector("#colour").value = res.colour || 'Firefox red';
}

document.addEventListener('DOMContentLoaded', restoreOptions);
Expand Down

0 comments on commit 6392240

Please sign in to comment.