From 92329580b29e9da7431023147ce7b1750162891e Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 10 Sep 2020 08:03:45 +0200 Subject: [PATCH] correct setting functions --- public/trivabble.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/public/trivabble.js b/public/trivabble.js index f471e06..8979b39 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -47,9 +47,14 @@ setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]); setConf("FLASH_LIGHT_COLOR", "#E3E"); + function isSetting(key) { + return Object.prototype.hasOwnProperty.call(Conf, key) || + Object.prototype.hasOwnProperty.call(localStorage, key); + } + function getSetting(key) { let type = undefined; - let value; + let value = undefined; /* get default value from configuration */ if (Object.prototype.hasOwnProperty.call(Conf, key)) { @@ -61,9 +66,13 @@ if (Object.prototype.hasOwnProperty.call(localStorage, key)) { value = localStorage.getItem(key); - /* get type from localStore if no default is set */ - if (type === "undefined") { - type = localStorage.getItem(key + "_type"); + /* get type from localStorage if no default is set */ + if (type === undefined) { + if (Object.prototype.hasOwnProperty.call(localStorage, key + "_key")) { + type = localStorage.getItem(key + "_type"); + } else { + type = "string"; + } } /* cast from string to type */ @@ -102,7 +111,7 @@ /* if not set type is defined from value */ if (type === undefined) { - typeof value; + type = typeof value; } /* storage value in localstorage */ -- 2.30.2