From ebe23c4d29ece449a8847128300d783714d945f4 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Wed, 22 Feb 2023 21:15:00 +0100 Subject: Update with count of "bad" requests --- background.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index 5295d9f..4d94e69 100644 --- a/background.js +++ b/background.js @@ -23,7 +23,7 @@ async function certInspectUpdate(requestId, tabId) { ); if (securityInfo.state !== "secure" || securityInfo.isUntrusted) { - setIcon("nope", tabId); + await tabInsecure(tabId); return; } @@ -34,12 +34,27 @@ async function certInspectUpdate(requestId, tabId) { for (let cert of certs) { if (rootCA.subject.includes(cert)) { - setIcon("nope", tabId); + await tabInsecure(tabId); return; } } - setIcon("ok", tabId); + await tabProbablySecure(tabId); +} + +async function tabProbablySecure(tabId) { + // only update if not already insecure + let t = await browser.browserAction.getBadgeText({ tabId }); + if (t === "") + setIcon("ok", tabId); +} + +async function tabInsecure(tabId) { + let t = await browser.browserAction.getBadgeText({ tabId }); + if (!t) + setIcon("nope", tabId); + let n = Number(t) + 1; + browser.browserAction.setBadgeText({ text: n.toString(), tabId }); } function setIcon(icon, tabId) { -- cgit