From e342264adf458a6ebeaa01a45688359dcf133945 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 5 Nov 2022 21:30:49 -0700 Subject: [PATCH] move `getSetting` from `background.js` -> `helpers.js` it will have use in `detailsInterface.js`, not just `background.js` (next patch). --- src/background.js | 23 ++--------------------- src/helpers.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/background.js b/src/background.js index 70031c5..fda8712 100644 --- a/src/background.js +++ b/src/background.js @@ -450,7 +450,7 @@ async function fillFields(settings, login, fields) { // build focus or submit request let focusOrSubmitRequest = { origin: new BrowserpassURL(settings.tab.url).origin, - autoSubmit: getSetting("autoSubmit", login, settings), + autoSubmit: helpers.getSetting("autoSubmit", login, settings), filledFields: filledFields, }; @@ -561,25 +561,6 @@ async function getFullSettings() { return settings; } -/** - * Get most relevant setting value - * - * @param string key Setting key - * @param object login Login object - * @param object settings Settings object - * @return object Setting value - */ -function getSetting(key, login, settings) { - if (typeof login.settings[key] !== "undefined") { - return login.settings[key]; - } - if (typeof settings.stores[login.store.id].settings[key] !== "undefined") { - return settings.stores[login.store.id].settings[key]; - } - - return settings[key]; -} - /** * Deep copy an object * @@ -968,7 +949,7 @@ async function parseFields(settings, login) { if (key === "secret" && lines.length) { login.fields.secret = lines[0]; } else if (key === "login") { - const defaultUsername = getSetting("username", login, settings); + const defaultUsername = helpers.getSetting("username", login, settings); login.fields[key] = defaultUsername || login.login.match(/([^\/]+)$/)[1]; } else { delete login.fields[key]; diff --git a/src/helpers.js b/src/helpers.js index e486abf..9e92dd3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -11,12 +11,32 @@ const BrowserpassURL = require("@browserpass/url"); module.exports = { prepareLogins, filterSortLogins, + getSetting, ignoreFiles, makeTOTP, }; //----------------------------------- Function definitions ----------------------------------// +/** + * Get most relevant setting value + * + * @param string key Setting key + * @param object login Login object + * @param object settings Settings object + * @return object Setting value + */ +function getSetting(key, login, settings) { + if (typeof login.settings[key] !== "undefined") { + return login.settings[key]; + } + if (typeof settings.stores[login.store.id].settings[key] !== "undefined") { + return settings.stores[login.store.id].settings[key]; + } + + return settings[key]; +} + /** * Get the deepest available domain component of a path *