diff --git a/background.js b/background.js index dd0eb3b..61d9212 100644 --- a/background.js +++ b/background.js @@ -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}`); @@ -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) { diff --git a/content.js b/content.js index 90733fa..1294512 100644 --- a/content.js +++ b/content.js @@ -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();