Update index.js

Updated icons to display properly
This commit is contained in:
Kenneth Hendricks 2024-11-10 16:20:21 -05:00 committed by GitHub
parent ad0f353d04
commit b3e30db0e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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")