From bbd952320ef1ecea41c455c7d966c63d446fde9b Mon Sep 17 00:00:00 2001 From: Kenneth Hendricks <50819541+kenhendricks00@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:52:29 -0500 Subject: [PATCH] Delete platform/chromium/pub directory --- platform/chromium/pub/index.html | 217 -------- platform/chromium/pub/index.js | 178 ------- platform/chromium/pub/settings-page.html | 605 ----------------------- platform/chromium/pub/settings-page.js | 281 ----------- platform/chromium/pub/warning-page.html | 212 -------- platform/chromium/pub/warning-page.js | 31 -- 6 files changed, 1524 deletions(-) delete mode 100644 platform/chromium/pub/index.html delete mode 100644 platform/chromium/pub/index.js delete mode 100644 platform/chromium/pub/settings-page.html delete mode 100644 platform/chromium/pub/settings-page.js delete mode 100644 platform/chromium/pub/warning-page.html delete mode 100644 platform/chromium/pub/warning-page.js diff --git a/platform/chromium/pub/index.html b/platform/chromium/pub/index.html deleted file mode 100644 index d9fa8af..0000000 --- a/platform/chromium/pub/index.html +++ /dev/null @@ -1,217 +0,0 @@ - - - - - - FMHY SafeGuard - - - -
-
-

FMHY SafeGuard

-
- -
-
- Status Icon -

Checking site status...

-
-

-
-

- Think this is a mistake? - Let us know. -

-
- - - - - diff --git a/platform/chromium/pub/index.js b/platform/chromium/pub/index.js deleted file mode 100644 index 9b3d09c..0000000 --- a/platform/chromium/pub/index.js +++ /dev/null @@ -1,178 +0,0 @@ -document.addEventListener("DOMContentLoaded", () => { - console.log("Popup loaded, preparing to check site status..."); - - const statusIcon = document.getElementById("status-icon"); - const statusMessage = document.getElementById("status-message"); - const errorMessage = document.getElementById("error-message"); - - // Helper function to normalize URLs (removes trailing slashes, query parameters, and fragments) - const normalizeUrl = (url) => { - const urlObj = new URL(url); - urlObj.search = ""; // Remove query parameters - urlObj.hash = ""; // Remove fragments - return urlObj.href.replace(/\/+$/, ""); // Remove trailing slash only - }; - - // Helper function to extract the root domain from a URL - function extractRootDomain(url) { - let urlObj = new URL(url); - return `${urlObj.protocol}//${urlObj.hostname}`; - } - - // Function to apply theme based on settings - function applyTheme() { - chrome.storage.sync.get("theme", ({ theme }) => { - if (theme === "dark") { - document.body.setAttribute("data-theme", "dark"); - } else if (theme === "light") { - document.body.setAttribute("data-theme", "light"); - } else { - const prefersDark = window.matchMedia( - "(prefers-color-scheme: dark)" - ).matches; - document.body.setAttribute( - "data-theme", - prefersDark ? "dark" : "light" - ); - } - }); - } - - // Apply theme on load - applyTheme(); - - // Get the active tab's URL - chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { - if (chrome.runtime.lastError || !tabs[0] || !tabs[0].url) { - handleError("No active tab found or URL is unavailable."); - return; - } - - const currentUrl = normalizeUrl(tabs[0].url); - const rootDomain = extractRootDomain(currentUrl); - console.log(`Active tab URL: ${currentUrl}, Root domain: ${rootDomain}`); - - // Send a message to the background script to check the site's status - chrome.runtime.sendMessage( - { action: "checkSiteStatus", url: currentUrl }, - (response) => { - if (chrome.runtime.lastError || !response || !response.status) { - handleError( - "Failed to retrieve site status from the background script." - ); - return; - } - - // Determine if the root domain or the full URL is marked as safe/starred - chrome.runtime.sendMessage( - { action: "checkSiteStatus", url: rootDomain }, - (isRootDomainMarked) => { - if (chrome.runtime.lastError || !isRootDomainMarked) { - handleError("Failed to check root domain status."); - return; - } - - if ( - isRootDomainMarked.status === response.status && - response.status !== "no_data" - ) { - // If both the root domain and the current URL share the same status, show the root domain in the message - handleStatusUpdate(response.status, rootDomain); - } else { - // Otherwise, show the current URL in the message - handleStatusUpdate(response.status, currentUrl); - } - } - ); - } - ); - }); - - function handleError(message) { - console.error(message); - errorMessage.textContent = `Error: ${message}`; - updateUI("error", "An error occurred while retrieving the site status."); - } - - /** - * Updates the UI based on the site status - * @param {string} status - The status of the site (e.g., "safe", "unsafe") - * @param {string} displayUrl - The URL or root domain to display in the message - */ - function handleStatusUpdate(status, displayUrl) { - switch (status) { - case "unsafe": - updateUI( - "unsafe", - `${displayUrl} is flagged as unsafe. Be cautious when interacting with this site.` - ); - break; - case "potentially_unsafe": - updateUI( - "potentially_unsafe", - `${displayUrl} is potentially unsafe. Proceed with caution.` - ); - break; - case "fmhy": - updateUI( - "fmhy", - `${displayUrl} is an FMHY related site. Proceed confidently.` - ); - break; - case "safe": - updateUI("safe", `${displayUrl} is safe to browse.`); - break; - case "starred": - updateUI( - "starred", - `${displayUrl} is a starred site.` - ); - break; - case "no_data": - updateUI( - "no_data", - `No data available for ${displayUrl}.` - ); - break; - default: - updateUI( - "unknown", - `An unknown status was received for ${displayUrl}.` - ); - } - } - - /** - * Updates the UI with the appropriate icon, message, and effects. - * @param {string} status - The status of the site (e.g., "safe", "unsafe"). - * @param {string} message - The message to display to the user. - */ - function updateUI(status, message) { - const icons = { - unsafe: "../res/icons/unsafe.png", - potentially_unsafe: "../res/icons/potentially_unsafe.png", - fmhy: "../res/icons/fmhy.png", - safe: "../res/icons/safe.png", - starred: "../res/icons/starred.png", - no_data: "../res/ext_icon_144.png", - error: "../res/icons/error.png", - unknown: "../res/ext_icon_144.png", - }; - - // Update the icon and message - statusIcon.src = icons[status] || icons["unknown"]; - statusMessage.innerHTML = message || "An unknown error occurred."; - - // Add a small animation when the status changes - statusIcon.classList.add("active"); - setTimeout(() => statusIcon.classList.remove("active"), 300); - - console.log(`UI updated: ${message}`); - } - - // Add settings button functionality - document.getElementById("settingsButton").addEventListener("click", () => { - // Open the settings page in a new tab - chrome.runtime.openOptionsPage(); - }); -}); diff --git a/platform/chromium/pub/settings-page.html b/platform/chromium/pub/settings-page.html deleted file mode 100644 index 3d8faec..0000000 --- a/platform/chromium/pub/settings-page.html +++ /dev/null @@ -1,605 +0,0 @@ - - - - - - FMHY SafeGuard - Settings - - - - -
-

FMHY SafeGuard Settings

- -
- -
-
-
Filterlist Statistics
-
- Last Updated: Today at 2:56:48 PM -
-
- -
-
-
Unsafe Sites
-
266
-
-
-
Potentially Unsafe Sites
-
46
-
-
-
Safe Sites
-
21901
-
-
- -
- Next update scheduled for: Checking... -
-
- - -
-
-
-

Theme

-

- Choose your preferred appearance mode -

-
-
- -
-
-
- - -
-
-
-

Warning Page

-

- Show warning page for unsafe sites -

-
- -
-
- - -
-
-
-

Auto-Update Filterlist

-

- Automatically update security filters -

-
-
- -
-
-
-
- - -
- -
- - -
- - -
- Settings saved successfully! -
- - - - diff --git a/platform/chromium/pub/settings-page.js b/platform/chromium/pub/settings-page.js deleted file mode 100644 index 4157a8d..0000000 --- a/platform/chromium/pub/settings-page.js +++ /dev/null @@ -1,281 +0,0 @@ -document.addEventListener("DOMContentLoaded", () => { - // Get all DOM elements - const themeSelect = document.getElementById("themeSelect"); - const warningToggle = document.getElementById("warningToggle"); - const updateFrequency = document.getElementById("updateFrequency"); - const saveButton = document.getElementById("saveSettings"); - const notification = document.getElementById("notification"); - const lastUpdated = document.getElementById("lastUpdated"); - const updateStatus = document.getElementById("updateStatus"); - - // Theme application function - function applyTheme(theme) { - if (theme === "system") { - const prefersDark = window.matchMedia( - "(prefers-color-scheme: dark)" - ).matches; - document.body.setAttribute("data-theme", prefersDark ? "dark" : "light"); - } else { - document.body.setAttribute("data-theme", theme); - } - } - - // Format date function - function formatDate(date) { - if (!date) return "Never"; - const d = new Date(date); - const now = new Date(); - const diffTime = Math.abs(now - d); - const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); - - if (diffDays === 0) { - return ( - "Today at " + - d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) - ); - } else if (diffDays === 1) { - return ( - "Yesterday at " + - d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) - ); - } else { - return ( - d.toLocaleDateString() + - " " + - d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) - ); - } - } - - // Calculate next update time - function calculateNextUpdate(lastUpdate, frequency) { - if (!lastUpdate) return "Not scheduled"; - const lastUpdateDate = new Date(lastUpdate); - let nextUpdate = new Date(lastUpdateDate); - - switch (frequency) { - case "daily": - nextUpdate.setDate(nextUpdate.getDate() + 1); - nextUpdate.setHours(0, 0, 0, 0); - break; - case "weekly": - nextUpdate.setDate(nextUpdate.getDate() + 7); - nextUpdate.setHours(0, 0, 0, 0); - break; - case "monthly": - nextUpdate.setMonth(nextUpdate.getMonth() + 1); - nextUpdate.setHours(0, 0, 0, 0); - break; - default: - return "Not scheduled"; - } - - const now = new Date(); - if (nextUpdate < now) { - return "Update pending..."; - } - - const timeUntil = nextUpdate - now; - const hoursUntil = Math.floor(timeUntil / (1000 * 60 * 60)); - const minutesUntil = Math.floor( - (timeUntil % (1000 * 60 * 60)) / (1000 * 60) - ); - - if (hoursUntil < 24) { - if (hoursUntil === 0) { - return `in ${minutesUntil} minutes`; - } else { - return `in ${hoursUntil}h ${minutesUntil}m`; - } - } else { - const days = Math.floor(hoursUntil / 24); - if (days === 1) { - return "tomorrow"; - } else { - return `in ${days} days`; - } - } - } - - // Update the UI with next update time - function updateNextUpdateStatus() { - chrome.storage.local.get({ lastUpdated: null }, (stats) => { - chrome.storage.sync.get({ updateFrequency: "daily" }, (settings) => { - const nextUpdateText = calculateNextUpdate( - stats.lastUpdated, - settings.updateFrequency - ); - - if (updateStatus) { - updateStatus.innerHTML = ` - - - - Next update ${nextUpdateText} - `; - } - }); - }); - } - - // Load filterlist stats - function loadFilterlistStats() { - chrome.storage.local.get( - { - unsafeFilterCount: 0, - potentiallyUnsafeFilterCount: 0, - safeSiteCount: 0, - lastUpdated: null, - }, - (stats) => { - console.log("Fetched stats:", stats); - - document.getElementById("unsafeFilterCount").textContent = - stats.unsafeFilterCount; - document.getElementById("potentiallyUnsafeFilterCount").textContent = - stats.potentiallyUnsafeFilterCount; - document.getElementById("safeSiteCount").textContent = - stats.safeSiteCount; - document.getElementById("lastUpdated").textContent = formatDate( - stats.lastUpdated - ); - - // Update the next update status - updateNextUpdateStatus(); - } - ); - } - - // Load settings function - function loadSettings() { - chrome.storage.sync.get( - { - theme: "system", - warningPage: true, - updateFrequency: "daily", - }, - (savedSettings) => { - if (themeSelect) themeSelect.value = savedSettings.theme; - if (warningToggle) warningToggle.checked = savedSettings.warningPage; - if (updateFrequency) - updateFrequency.value = savedSettings.updateFrequency; - - // Apply theme - applyTheme(savedSettings.theme); - - // Load filterlist stats after settings are loaded - loadFilterlistStats(); - } - ); - } - - // Show notification function - function showNotification(message, isError = false) { - if (notification) { - notification.textContent = message; - if (isError) { - notification.style.background = - "linear-gradient(120deg, #ff6b6b, #ff8787)"; - } else { - notification.style.background = - "linear-gradient(120deg, var(--accent-purple), var(--accent-blue))"; - } - notification.classList.add("show"); - setTimeout(() => { - notification.classList.remove("show"); - }, 3000); - } - } - - // Save settings function - function saveSettings() { - console.log("Save button clicked, attempting to save settings..."); - - if (!themeSelect || !warningToggle || !updateFrequency) { - console.error( - "Missing form elements. Ensure all elements are properly defined." - ); - showNotification("Error saving settings: Missing form elements", true); - return; - } - - const settings = { - theme: themeSelect.value, - warningPage: warningToggle.checked, - updateFrequency: updateFrequency.value, - }; - - console.log("Settings to save:", settings); - - chrome.storage.sync.set(settings, () => { - if (chrome.runtime.lastError) { - console.error( - "Error saving settings:", - chrome.runtime.lastError.message - ); - showNotification("Error saving settings", true); - return; - } - - console.log("Settings saved successfully."); - - // Show success notification - showNotification("Settings saved successfully!"); - - // Apply theme immediately - applyTheme(settings.theme); - console.log("Theme applied:", settings.theme); - - // Update next update status - updateNextUpdateStatus(); - - // Notify background script about settings change - chrome.runtime.sendMessage( - { type: "settingsUpdated", settings: settings }, - () => { - if (chrome.runtime.lastError) { - console.error( - "Error notifying background script:", - chrome.runtime.lastError.message - ); - } else { - console.log("Background script notified about settings change."); - } - } - ); - }); - } - - // Event Listeners - if (saveButton) { - saveButton.addEventListener("click", saveSettings); - } - - if (themeSelect) { - themeSelect.addEventListener("change", (e) => { - applyTheme(e.target.value); - }); - } - - // System theme change listener - window - .matchMedia("(prefers-color-scheme: dark)") - .addEventListener("change", (e) => { - if (themeSelect && themeSelect.value === "system") { - applyTheme("system"); - } - }); - - // Listen for filterlist updates from background script - chrome.runtime.onMessage.addListener((message) => { - if (message.type === "filterlistUpdated") { - loadFilterlistStats(); - } - }); - - // Update the status every minute - setInterval(updateNextUpdateStatus, 60000); - - // Load settings when page loads - loadSettings(); -}); diff --git a/platform/chromium/pub/warning-page.html b/platform/chromium/pub/warning-page.html deleted file mode 100644 index 5cf1733..0000000 --- a/platform/chromium/pub/warning-page.html +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - FMHY SafeGuard - Warning - - - - - -
-

FMHY SafeGuard

-
- Warning -

-

- This site has been flagged as unsafe.
- Be cautious when interacting with this site. -

-
- - -
-
- -
- - diff --git a/platform/chromium/pub/warning-page.js b/platform/chromium/pub/warning-page.js deleted file mode 100644 index c90ec7a..0000000 --- a/platform/chromium/pub/warning-page.js +++ /dev/null @@ -1,31 +0,0 @@ -document.addEventListener("DOMContentLoaded", () => { - const urlParams = new URLSearchParams(window.location.search); - const unsafeUrl = urlParams.get("url") || "unknown site"; - document.getElementById("unsafeUrl").textContent = unsafeUrl; - console.log(`Warning page loaded for URL: ${unsafeUrl}`); - - document.getElementById("goBack").addEventListener("click", () => { - console.log("User clicked Go Back."); - window.history.go(-2); - }); - - document.getElementById("proceed").addEventListener("click", () => { - if (confirm("Are you sure you want to proceed? This site may be unsafe.")) { - chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { - const tab = tabs[0]; - - console.log(`Sending proceedAnyway message for tab ${tab.id}`); - chrome.runtime.sendMessage( - { - action: "proceedAnyway", - tabId: tab.id, - }, - () => { - console.log("Proceed flag set, navigating to unsafe URL..."); - chrome.tabs.update(tab.id, { url: unsafeUrl }); - } - ); - }); - } - }); -});