mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
rename from some options to favourite colour
This commit is contained in:
4
favourite-colour/README.md
Normal file
4
favourite-colour/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Favourite Colour
|
||||
|
||||
Shows and stores your favourite color, in chrome.storage.local
|
||||
in the about:addons page for the addon.
|
||||
5
favourite-colour/background.js
Normal file
5
favourite-colour/background.js
Normal file
@@ -0,0 +1,5 @@
|
||||
function handleClick() {
|
||||
chrome.runtime.openOptionsPage();
|
||||
}
|
||||
|
||||
chrome.browserAction.onClicked.addListener(handleClick);
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "favourite-colour@mozilla.org",
|
||||
"id": "some-options@mozilla.org",
|
||||
"strict_min_version": "47.0a1"
|
||||
}
|
||||
},
|
||||
@@ -16,7 +16,7 @@
|
||||
"manifest_version": 2,
|
||||
"name": "Favourite colour",
|
||||
"options_ui": {
|
||||
"page": "options.html",
|
||||
"page": "options.html"
|
||||
},
|
||||
"permissions": ["storage"],
|
||||
"version": "1.0"
|
||||
14
favourite-colour/options.js
Normal file
14
favourite-colour/options.js
Normal file
@@ -0,0 +1,14 @@
|
||||
function saveOptions(e) {
|
||||
chrome.storage.local.set({
|
||||
colour: document.querySelector("#colour").value
|
||||
});
|
||||
}
|
||||
|
||||
function restoreOptions() {
|
||||
chrome.storage.local.get('colour', (res) => {
|
||||
document.querySelector("#colour").value = res.colour || 'Firefox red';
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', restoreOptions);
|
||||
document.querySelector("form").addEventListener("submit", saveOptions);
|
||||
Reference in New Issue
Block a user