mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
* add in managed example * Updated favourite-colour README to point to the storage.managed documentation
22 lines
637 B
JavaScript
22 lines
637 B
JavaScript
function saveOptions(e) {
|
|
browser.storage.sync.set({
|
|
colour: document.querySelector("#colour").value
|
|
});
|
|
e.preventDefault();
|
|
}
|
|
|
|
function restoreOptions() {
|
|
var storageItem = browser.storage.managed.get('colour');
|
|
storageItem.then((res) => {
|
|
document.querySelector("#managed-colour").innerText = res.colour;
|
|
});
|
|
|
|
var gettingItem = browser.storage.sync.get('colour');
|
|
gettingItem.then((res) => {
|
|
document.querySelector("#colour").value = res.colour || 'Firefox red';
|
|
});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', restoreOptions);
|
|
document.querySelector("form").addEventListener("submit", saveOptions);
|