Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use async/await in options.js #457

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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