From 308d9585783d793aad34f04fe2c89e96149510cb Mon Sep 17 00:00:00 2001
From: ikipatang <5412352+ikipatang@users.noreply.github.com>
Date: Mon, 27 Nov 2017 23:04:10 +0100
Subject: [PATCH] PageAction: create settings input
---
src/background.js | 4 +---
src/options/options.html | 1 +
src/options/options.js | 42 ++++++++++++++++++++++++++--------------
3 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/src/background.js b/src/background.js
index 1e4d8c7..bc5dfe8 100644
--- a/src/background.js
+++ b/src/background.js
@@ -37,9 +37,7 @@ function shareCurrentTab(tab) {
*/
function showPageAction(tabId){
browser.storage.local.get().then((storage) => {
- if(storage.pageAction){
- browser.pageAction.show(tabId);
- }
+ storage.pageAction ? browser.pageAction.show(tabId) : browser.pageAction.hide(tabId);
});
}
diff --git a/src/options/options.html b/src/options/options.html
index 681b6de..20aeb68 100644
--- a/src/options/options.html
+++ b/src/options/options.html
@@ -9,6 +9,7 @@
URL:
+ Address Bar:
diff --git a/src/options/options.js b/src/options/options.js
index 481e2f5..e61677b 100644
--- a/src/options/options.js
+++ b/src/options/options.js
@@ -1,26 +1,40 @@
-/*
-Store options UI using browser.storage.local.
-*/
+/**
+ * Store options UI using browser.storage.local.
+ * @return {void} -
+ */
function storeSettings() {
- const url = document.querySelector("#url");
- // console.log('storeSettings url');
- // console.log(url);
- browser.storage.local.set({
- url: url.value,
- });
+ const settings = {
+ url: document.querySelector("#url").value,
+ pageAction: document.querySelector("#pageAction").checked,
+ };
+ // console.log('storeSettings settings');
+ // console.log(settings);
+ browser.storage.local.set(settings);
}
-/*
-Update the options UI with the settings values retrieved from storage,
-or the default settings if the stored settings are empty.
-*/
+/**
+ * Update the options UI with the settings values retrieved from storage,
+ * or the default settings if the stored settings are empty.
+ * @param {object} restoredSettings -
+ * @return {void} -
+ */
function updateUI(restoredSettings) {
const url = document.querySelector("#url");
+ url.value = restoredSettings.url;
// console.log('restoredSettings url');
// console.log(url);
- url.value = restoredSettings.url || "";
+
+ const pageAction = document.querySelector("#pageAction");
+ pageAction.checked = restoredSettings.pageAction;
+ // console.log('restoredSettings pageAction');
+ // console.log(pageAction);
}
+/**
+ * Display on error
+ * @param {object} error -
+ * @return {void} -
+ */
function onError(e) {
console.error(e);
}