From b3e30db0e67dcd74311a822ca9906222f526da62 Mon Sep 17 00:00:00 2001 From: Kenneth Hendricks <50819541+kenhendricks00@users.noreply.github.com> Date: Sun, 10 Nov 2024 16:20:21 -0500 Subject: [PATCH] Update index.js Updated icons to display properly --- src/pub/index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pub/index.js b/src/pub/index.js index 4dacee5..58e7455 100644 --- a/src/pub/index.js +++ b/src/pub/index.js @@ -51,6 +51,9 @@ document.addEventListener("DOMContentLoaded", async () => { return; // Skip further processing since it's an internal page } + // Extract the root URL for display + const rootUrl = extractRootUrl(currentUrl); + // Send a message to the background script to check the site's status const response = await browserAPI.runtime.sendMessage({ action: "checkSiteStatus", @@ -63,13 +66,28 @@ document.addEventListener("DOMContentLoaded", async () => { ); } - handleStatusUpdate(response.status, currentUrl); + handleStatusUpdate(response.status, rootUrl); } catch (error) { console.error("Error while checking site status:", error); errorMessage.textContent = `Error: ${error.message}`; updateUI("error", "An error occurred while retrieving the site status."); } + /** + * Extracts the root URL from a full URL. + * @param {string} url - The full URL to extract the root from. + * @returns {string} - The root URL. + */ + function extractRootUrl(url) { + try { + const urlObj = new URL(url); + return `${urlObj.protocol}//${urlObj.hostname}`; + } catch (error) { + console.warn("Failed to extract root URL:", error); + return url; // Fallback to full URL if extraction fails + } + } + /** * Updates the UI based on the site status * @param {string} status - The status of the site (e.g., "safe", "unsafe")