Skip to content

Commit c4fea64

Browse files
committed
Implement badgeText to show loginCount
Show how many logins are available for the current Tab in the Badge
1 parent b9bef95 commit c4fea64

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

background.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ async function autoFillSecrets(message, sender) {
7575

7676
const vault = new Vault(vaultToken, vaultAddress);
7777

78+
let loginCount = 0;
79+
7880
for (let secret of secretList) {
7981
const secretKeys = await vault.list(`/secret/metadata/vaultPass/${secret}`);
8082
for (let key of secretKeys.data.keys) {
83+
var pattern = new RegExp(key);
84+
var patternMatches = pattern.test(hostname);
85+
// If the key is an exact match to the current hostname --> autofill
8186
if (hostname === clearHostname(key)) {
8287
const credentials = await vault.get(`/secret/data/vaultPass/${secret}${key}`);
8388

@@ -86,11 +91,16 @@ async function autoFillSecrets(message, sender) {
8691
username: credentials.data.data.username,
8792
password: credentials.data.data.password,
8893
});
89-
90-
return;
94+
}
95+
if (patternMatches) {
96+
loginCount++;
9197
}
9298
}
9399
}
100+
if (loginCount == 0) {
101+
return;
102+
}
103+
chrome.action.setBadgeText({text: `${loginCount}`,tabId: sender.tab.id});
94104
}
95105

96106
chrome.runtime.onMessage.addListener(function(message, sender) {

content.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ function handleFillCredits(request) {
9191
}
9292

9393
function fillForm() {
94-
if (document.querySelectorAll('input[type=\'password\']').length) {
95-
chrome.runtime.sendMessage({
96-
type: 'auto_fill_secrets',
97-
});
98-
}
94+
chrome.runtime.sendMessage({
95+
type: 'auto_fill_secrets',
96+
});
9997
}
10098

10199
fillForm();

0 commit comments

Comments
 (0)