Skip to content

Commit 5a47c59

Browse files
committed
feat: prefill host when creating new password
1 parent 176a418 commit 5a47c59

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/helpers/base.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
isChrome,
3636
makeTOTP,
3737
parseAuthUrl,
38+
getCurrentUrl,
3839
prepareLogin,
3940
prepareLogins,
4041
unsecureRequestWarning,
@@ -148,6 +149,22 @@ function parseAuthUrl(url) {
148149
return null;
149150
}
150151

152+
/**
153+
* Returns current url
154+
* @param object settings Settings object to use
155+
* @returns string
156+
*/
157+
function getCurrentUrl(settings) {
158+
let url = "";
159+
const authUrl = parseAuthUrl(window?.location?.href ?? null);
160+
if (settings.authRequested && authUrl) {
161+
url = new BrowserpassURL(authUrl);
162+
} else {
163+
url = new BrowserpassURL(settings.origin);
164+
}
165+
return url
166+
}
167+
151168
/**
152169
* Prepare list of logins based on provided files
153170
*

src/popup/addEditInterface.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ function AddEditInterface(settingsModel) {
284284
} else {
285285
// view instance should be a Login
286286
loginObj = new Login(settings);
287+
288+
const url = helpers.getCurrentUrl(settings);
289+
290+
// prefill the host of the current tab
291+
loginObj.login = url.isValid ? url.hostname : "";
287292
}
288293

289294
// set the storePath and get tree dirs

src/popup/searchinterface.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,7 @@ function SearchInterface(popup) {
3333
function view(ctl, params) {
3434
var self = this;
3535

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;
36+
const host = helpers.getCurrentUrl(this.popup.settings).hostname;
4537

4638
return m(
4739
"form.part.search",

0 commit comments

Comments
 (0)