From f5c5af92ca735a47510a9d7e92c286f4a3593062 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 7 Nov 2020 17:02:24 +0100 Subject: [PATCH] #32 Added reset Button to options page and fixed settings script --- src/html/settings.html | 3 ++- src/javascript/settings.js | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/html/settings.html b/src/html/settings.html index f273bd9..6157160 100644 --- a/src/html/settings.html +++ b/src/html/settings.html @@ -16,7 +16,8 @@
- + + diff --git a/src/javascript/settings.js b/src/javascript/settings.js index 9f2e1b1..a559277 100644 --- a/src/javascript/settings.js +++ b/src/javascript/settings.js @@ -1,11 +1,11 @@ import { getGlobalStorageProvider } from "./settings/storageProvider"; import { onReady } from "./utils/helpers"; -const OPTION_SELECTOR = '.extension-option' +const OPTION_SELECTOR = 'input[type="checkbox"'; function storeOptions() { document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => { - getGlobalStorageProvider().setData(optionElement.id, optionElement.check); + getGlobalStorageProvider().setData(optionElement.id, optionElement.checked); }); } @@ -19,9 +19,26 @@ function restoreOptions() { }); } +function resetOptions() { + document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => { + let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false; + + optionElement.checked = defaultValue; + }); +} + onReady(() => { // register Store Button - document.getElementById('saveBtn').addEventListener('click', storeOptions); + document.getElementById('btnSave').addEventListener('click', event => { + event.preventDefault(); + storeOptions(); + }); + + document.getElementById('btnReset').addEventListener('click', event => { + event.preventDefault(); + resetOptions(); + storeOptions(); + }) // try restore options restoreOptions();