Skip to content

Commit

Permalink
Implement badgeText to show loginCount
Browse files Browse the repository at this point in the history
Show how many logins are available for the current Tab in the Badge
  • Loading branch information
mulbc committed Aug 12, 2021
1 parent b9bef95 commit c4fea64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 12 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ async function autoFillSecrets(message, sender) {

const vault = new Vault(vaultToken, vaultAddress);

let loginCount = 0;

for (let secret of secretList) {
const secretKeys = await vault.list(`/secret/metadata/vaultPass/${secret}`);
for (let key of secretKeys.data.keys) {
var pattern = new RegExp(key);
var patternMatches = pattern.test(hostname);
// If the key is an exact match to the current hostname --> autofill
if (hostname === clearHostname(key)) {
const credentials = await vault.get(`/secret/data/vaultPass/${secret}${key}`);

Expand All @@ -86,11 +91,16 @@ async function autoFillSecrets(message, sender) {
username: credentials.data.data.username,
password: credentials.data.data.password,
});

return;
}
if (patternMatches) {
loginCount++;
}
}
}
if (loginCount == 0) {
return;
}
chrome.action.setBadgeText({text: `${loginCount}`,tabId: sender.tab.id});
}

chrome.runtime.onMessage.addListener(function(message, sender) {
Expand Down
8 changes: 3 additions & 5 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ function handleFillCredits(request) {
}

function fillForm() {
if (document.querySelectorAll('input[type=\'password\']').length) {
chrome.runtime.sendMessage({
type: 'auto_fill_secrets',
});
}
chrome.runtime.sendMessage({
type: 'auto_fill_secrets',
});
}

fillForm();

0 comments on commit c4fea64

Please sign in to comment.