From c18c2252ddafcc53e201395e51fdbf1c95b6c8fc Mon Sep 17 00:00:00 2001 From: Dan TS Date: Thu, 22 Dec 2022 13:52:17 -0800 Subject: [PATCH 1/4] dashboard.js dashboard.html: Font size for total count changes based on size --- source/dashboard.html | 1 - source/static/dashboard.js | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/source/dashboard.html b/source/dashboard.html index 9f0e147..9b42a0a 100644 --- a/source/dashboard.html +++ b/source/dashboard.html @@ -12,7 +12,6 @@ border: 30px solid #9336E5; text-align: center; font-family: 'THICCBOI-Bold'; - font-size: 123px; line-height: 310px; margin: auto; } diff --git a/source/static/dashboard.js b/source/static/dashboard.js index 16f440e..4ff9488 100644 --- a/source/static/dashboard.js +++ b/source/static/dashboard.js @@ -1,23 +1,47 @@ // convenience function to stringify large numbers to local formats with commas etc. const formatNumber = (num) => new Intl.NumberFormat().format(num); +// takes an integer and returns a string to set font size +const getFontSizeForTotal = (num) => { + const oneToThreeDigits = '123px'; + const fourDigits = '110px'; + const fiveDigits = '90px'; + const sixDigits = '75px'; + const sevenDigits = '60px'; + + if (num >= 10**6) { + result = sevenDigits; + } else if (num >= 10**5) { + result = sixDigits; + } else if (num >= 10**4) { + result = fiveDigits; + } else if (num >= 10**3) { + result = fourDigits; + } else { + result = oneToThreeDigits; + } + + return result; +}; + window.addEventListener("load", async function() { // get dashboard number for total URLs visited from local storage chrome.storage.local.get(["totalURLsVisited"]).then((result) => { const {totalURLsVisited = 1} = result; - // get HTML elements of dashboard numbers to fill in - const localUniqueURLsScannedCount = document.getElementById("local-unique-urls-scanned-count"); + // set and format *total* URLs + const formattedTotalURLsVisited = formatNumber(totalURLsVisited); const localURLsScannedCount = document.getElementById("local-urls-scanned-count"); - // Ratio 0.177 based on Interlock data sources - const uniqueURLsVisited = Math.ceil(totalURLsVisited * 0.177) || 1; + localURLsScannedCount.style.fontSize = getFontSizeForTotal(totalURLsVisited); + localURLsScannedCount.innerHTML = formattedTotalURLsVisited; - const formattedTotalURLsVisited = formatNumber(totalURLsVisited); + // set and format unique URLs const formattedUniqueURLsVisited = formatNumber(uniqueURLsVisited); + const localUniqueURLsScannedCount = document.getElementById("local-unique-urls-scanned-count"); + const uniqueURLsVisited = Math.ceil(totalURLsVisited * 0.177) || 1; // Ratio 0.177 based on Interlock data sources localUniqueURLsScannedCount.innerHTML = `≈ ${formattedUniqueURLsVisited}`; - localURLsScannedCount.innerHTML = formattedTotalURLsVisited; }); // get dashboard number for malicious URLs visited from local storage From a1ec49f750ff2d9537da66858367a74560ad49c0 Mon Sep 17 00:00:00 2001 From: Dan TS Date: Thu, 22 Dec 2022 13:53:20 -0800 Subject: [PATCH 2/4] background.js: On installation or update, extension opens a new tab --- source/background.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/source/background.js b/source/background.js index af4eb10..b78c593 100644 --- a/source/background.js +++ b/source/background.js @@ -122,6 +122,38 @@ chrome.runtime.onMessage.addListener( return true; } - }); + } +); +/** + * This listener does two things: + * - Opens the ThreatSlayer welcome page on installing the extension, and + * - Opens the welcome page on update + */ +chrome.runtime.onInstalled.addListener(function openWelcomeTab(details) { + const reason = details.reason + console.log('reason', reason); + + switch (reason) { + // user has installed ThreatSlayer + case 'install': + chrome.tabs.create({ + // TODO change this URL + url: 'https://yahoo.com' + }); + break; + // user has updated their ThreatSlayer version + case 'update': + chrome.tabs.create({ + // TODO change this URL + url: 'https://yahoo.com' + }); + break; + case 'chrome_update': + case 'shared_module_update': + default: + break; + } +}); + \ No newline at end of file From 1f074384d394af0ee0178db09477be22168e8a43 Mon Sep 17 00:00:00 2001 From: Dan TS Date: Fri, 23 Dec 2022 10:31:08 -0800 Subject: [PATCH 3/4] dashboard.js: fixed typos, added dynamic size for dashboard nums for unique sites visited --- source/static/dashboard.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/source/static/dashboard.js b/source/static/dashboard.js index 4ff9488..e9ab835 100644 --- a/source/static/dashboard.js +++ b/source/static/dashboard.js @@ -9,6 +9,8 @@ const getFontSizeForTotal = (num) => { const sixDigits = '75px'; const sevenDigits = '60px'; + let result; + if (num >= 10**6) { result = sevenDigits; } else if (num >= 10**5) { @@ -24,23 +26,42 @@ const getFontSizeForTotal = (num) => { return result; }; +// takes an integer and returns a string to set font size +const getFontSizeForUnique = (num) => { + const defaultSize = '56px'; + const sixDigits = '40px'; + + let result; + + if (num >= 10**6) { + result = sixDigits; + } else { + result = defaultSize; + } + + return result; +}; + window.addEventListener("load", async function() { // get dashboard number for total URLs visited from local storage chrome.storage.local.get(["totalURLsVisited"]).then((result) => { const {totalURLsVisited = 1} = result; + // get HTML elements for total and unique URL counts + const localURLsScannedCount = document.getElementById("local-urls-scanned-count"); + const localUniqueURLsScannedCount = document.getElementById("local-unique-urls-scanned-count"); + // set and format *total* URLs const formattedTotalURLsVisited = formatNumber(totalURLsVisited); - const localURLsScannedCount = document.getElementById("local-urls-scanned-count"); localURLsScannedCount.style.fontSize = getFontSizeForTotal(totalURLsVisited); localURLsScannedCount.innerHTML = formattedTotalURLsVisited; // set and format unique URLs - const formattedUniqueURLsVisited = formatNumber(uniqueURLsVisited); - const localUniqueURLsScannedCount = document.getElementById("local-unique-urls-scanned-count"); const uniqueURLsVisited = Math.ceil(totalURLsVisited * 0.177) || 1; // Ratio 0.177 based on Interlock data sources + const formattedUniqueURLsVisited = formatNumber(uniqueURLsVisited); + localUniqueURLsScannedCount.style.fontSize = getFontSizeForUnique(uniqueURLsVisited); localUniqueURLsScannedCount.innerHTML = `≈ ${formattedUniqueURLsVisited}`; }); @@ -94,7 +115,6 @@ window.addEventListener("load", async function() { toggleLabel.style.opacity = 0.4; notYet.style.display = 'inherit'; }, 250); - } } From 9608e516802f2ccd9a2c97a99340369466bbf2f5 Mon Sep 17 00:00:00 2001 From: Dan TS Date: Fri, 23 Dec 2022 10:36:58 -0800 Subject: [PATCH 4/4] dashboard.html: minor update bc one of the font sizes is dynamically generated --- source/dashboard.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/dashboard.html b/source/dashboard.html index 9b42a0a..10ebe6c 100644 --- a/source/dashboard.html +++ b/source/dashboard.html @@ -40,7 +40,6 @@ } .statistic-value { font-family: 'THICCBOI'; - font-size: 56px; color: #222222; margin-top: 0; } @@ -80,7 +79,7 @@

Malicious Sites Detected

-

+

0