3 Commits

Author SHA1 Message Date
5573c45158 debug: try exporting a function
i don't understand why i can't export my enum.
2022-11-06 01:13:55 -07:00
73a405c008 define SettingScope 2022-11-06 00:38:37 -07:00
4c7d3533a3 refactor: move getSetting from background.js -> helpers.js
this is because i plan to use it in `detailsInterface.js`
2022-11-05 23:55:38 -07:00
2 changed files with 37 additions and 24 deletions

View File

@@ -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 (or null)
* @param object settings Settings object
* @return object Setting value
*/
function getSetting(key, login, settings) {
if (login !== null && 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
*
@@ -743,7 +724,7 @@ async function handleMessage(settings, message, sendResponse) {
}
break;
case "copyOTP":
if (getSetting("enableOTP", null, settings)) {
if (settings.enableOTP) {
try {
if (!message.login.fields.otp) {
throw new Exception("No OTP seed available");
@@ -815,7 +796,7 @@ async function handleMessage(settings, message, sendResponse) {
// copy OTP token after fill
if (
getSetting("enableOTP", null, settings) &&
settings.enableOTP &&
typeof message.login !== "undefined" &&
message.login.fields.hasOwnProperty("otp")
) {
@@ -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];
@@ -982,7 +963,7 @@ async function parseFields(settings, login) {
}
// preprocess otp
if (getSetting("enableOTP", null, settings) && login.fields.hasOwnProperty("otp")) {
if (settings.enableOTP && login.fields.hasOwnProperty("otp")) {
if (login.fields.otp.match(/^otpauth:\/\/.+/i)) {
// attempt to parse otp data as URI
try {

View File

@@ -11,12 +11,44 @@ const BrowserpassURL = require("@browserpass/url");
module.exports = {
prepareLogins,
filterSortLogins,
getSetting,
ignoreFiles,
makeTOTP,
expTest,
};
function expTest(foo) {
return foo * 2;
}
const SettingScope = {
// query a setting first from the login, then the store, then globally
Login: "login",
// query a setting first from the store, then globally
Store: "store",
};
//----------------------------------- 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
*