From 5b85c214e0b0909ac3618a465eef85129b5696eb Mon Sep 17 00:00:00 2001 From: SamuZad Date: Sat, 14 Jan 2023 13:44:27 +0000 Subject: [PATCH] add debounce to search --- popup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/popup.js b/popup.js index 94c7047..32f8bd9 100644 --- a/popup.js +++ b/popup.js @@ -5,6 +5,7 @@ const notify = new Notify(document.querySelector('#notify')); var resultList = document.getElementById('resultList'); var searchInput = document.getElementById('vault-search'); var searchRegex, vaultServerAdress, vaultToken, secretList; +let searchKickoff; async function mainLoaded() { var tabs = await browser.tabs.query({ active: true, currentWindow: true }); @@ -95,12 +96,15 @@ async function querySecrets(searchString, manualSearch) { } const searchHandler = function (e) { + clearTimeout(searchKickoff); if (e.key === 'Enter') { mainLoaded() + } else { + searchKickoff = setTimeout(() => mainLoaded(), 1000); } }; -searchInput.addEventListener('keypress', searchHandler); +searchInput.addEventListener('keyup', searchHandler); function addCredentialsToList(credentials, credentialName, list) { const item = document.createElement('li');