Skip to content

Commit 32bedd5

Browse files
authored
Prefill host when creating new password (#383)
1 parent bf76c28 commit 32bedd5

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

src/helpers/base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function parseAuthUrl(url) {
148148
return null;
149149
}
150150

151+
151152
/**
152153
* Prepare list of logins based on provided files
153154
*

src/helpers/ui.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const m = require("mithril");
55
const dialog = require("../popup/modalDialog");
66
const notify = require("../popup/notifications");
77
const helpers = require("../helpers/base");
8+
const BrowserpassURL = require("@browserpass/url");
89

910
const containsNumbersRegEx = RegExp(/[0-9]/);
1011
const containsSymbolsRegEx = RegExp(/[\p{P}\p{S}]/, "u");
@@ -13,6 +14,7 @@ module.exports = {
1314
handleError,
1415
highlight,
1516
withLogin,
17+
getCurrentUrl
1618
};
1719

1820
//----------------------------------- Function definitions ----------------------------------//
@@ -152,3 +154,19 @@ async function withLogin(action, params = {}) {
152154
handleError(e);
153155
}
154156
}
157+
158+
/**
159+
* Returns current url
160+
* @param object settings Settings object to use
161+
* @returns object Instance of BrowserpassURL
162+
*/
163+
function getCurrentUrl(settings) {
164+
let url;
165+
const authUrl = helpers.parseAuthUrl(window?.location?.href ?? null);
166+
if (settings.authRequested && authUrl) {
167+
url = new BrowserpassURL(authUrl);
168+
} else {
169+
url = new BrowserpassURL(settings.origin);
170+
}
171+
return url
172+
}

src/popup/addEditInterface.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ function AddEditInterface(settingsModel) {
305305
} else {
306306
// view instance should be a Login
307307
loginObj = new Login(settings);
308+
309+
const url = helpersUI.getCurrentUrl(settings);
310+
311+
// prefill the host of the current tab
312+
loginObj.login = url.isValid ? url.hostname : "";
308313
}
309314

310315
// set the storePath and get tree dirs

src/popup/searchinterface.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = SearchInterface;
33
const BrowserpassURL = require("@browserpass/url");
44
const dialog = require("./modalDialog");
55
const helpers = require("../helpers/base");
6+
const helpersUI = require("../helpers/ui");
67
const m = require("mithril");
78

89
/**
@@ -33,15 +34,8 @@ function SearchInterface(popup) {
3334
function view(ctl, params) {
3435
var self = this;
3536

36-
let url = "";
37-
const authUrl = helpers.parseAuthUrl(window?.location?.href ?? null);
38-
if (this.popup.settings.authRequested && authUrl) {
39-
url = new BrowserpassURL(authUrl);
40-
} else {
41-
url = new BrowserpassURL(this.popup.settings.origin);
42-
}
43-
44-
const host = url.hostname;
37+
const url = helpersUI.getCurrentUrl(this.popup.settings);
38+
const host = url.isValid ? url.hostname : "";
4539

4640
return m(
4741
"form.part.search",

0 commit comments

Comments
 (0)