From 7d533d4d4ae4b4bacb7b362f9dd1a88f0196f8f3 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Mon, 17 Sep 2018 22:10:43 -0500 Subject: [PATCH] Fix select default option extraction --- js/usercss.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/js/usercss.js b/js/usercss.js index 1cfdd142..64a708a6 100644 --- a/js/usercss.js +++ b/js/usercss.js @@ -194,30 +194,18 @@ var usercss = (() => { state.errorPrefix = 'Invalid JSON: '; parseJSONValue(state); state.errorPrefix = ''; - const extractDefault = text => { - if (text.endsWith('*')) { - return text.slice(0, -1); + const extractDefaultOption = (key, value) => { + if (key.endsWith('*')) { + const option = createOption(key.slice(0, -1), value); + result.default = option.name; + return option; } - return false; + return createOption(key, value); }; if (Array.isArray(state.value)) { - result.options = state.value.map(text => { - const isDefault = extractDefault(text); - if (isDefault) { - result.default = isDefault; - } - return createOption(isDefault || text); - }); + result.options = state.value.map(k => extractDefaultOption(k)); } else { - result.options = Object.keys(state.value).map(k => { - const isDefault = extractDefault(k); - const value = state.value[k]; - if (isDefault) { - k = isDefault; - result.default = k; - } - return createOption(k, value); - }); + result.options = Object.keys(state.value).map(k => extractDefaultOption(k, state.value[k])); } if (result.default === null) { result.default = (result.options[0] || {}).name || '';