feat: Enhance domain management and configuration in the extension

- Introduce default configuration settings for API key, domains database URL, update interval, and warning message template in background.js and options.js.
- Update domains database URL to a new source for improved reliability.
- Refactor domain management UI in domains_management.js to support adding, editing, and removing trusted and blocked domains with enhanced user experience.
- Implement search functionality for filtering domains in the management interface.
- Improve status messaging for user feedback during domain operations.
This commit is contained in:
becarta
2025-05-10 03:52:10 +02:00
parent f757b4585a
commit 87506ae85a
6 changed files with 260 additions and 63 deletions

View File

@@ -11,35 +11,35 @@ document.addEventListener("DOMContentLoaded", function () {
console.error("⚠️ Element with ID 'warningTemplate' not found in options.html!");
}
// Default values
const defaultValues = {
safeBrowsingApiKey: "",
domainsDBURL: "https://raw.githubusercontent.com/rrpbergsma/EnterpriseAppProtection/refs/heads/main/domains.json",
// Default configuration
const DEFAULT_CONFIG = {
apiKey: '',
domainsDBURL: 'https://git.365devnet.eu/365DevNet/EnterpriseAppProtection/raw/branch/main/domains.json',
updateInterval: 24,
warningTemplate: "Warning: This link claims to be {app} but goes to an unofficial domain."
warningTemplate: 'Warning: This link claims to be {app} but goes to an unofficial domain.'
};
// Load stored settings and apply defaults where needed
chrome.storage.local.get(["safeBrowsingApiKey", "domainsDBURL", "updateInterval", "warningTemplate"], function (data) {
if (apiKeyElement) apiKeyElement.value = data.safeBrowsingApiKey || defaultValues.safeBrowsingApiKey;
if (domainsDBURLElement) domainsDBURLElement.value = data.domainsDBURL || defaultValues.domainsDBURL;
if (updateIntervalElement) updateIntervalElement.value = data.updateInterval || defaultValues.updateInterval;
if (apiKeyElement) apiKeyElement.value = data.safeBrowsingApiKey || DEFAULT_CONFIG.apiKey;
if (domainsDBURLElement) domainsDBURLElement.value = data.domainsDBURL || DEFAULT_CONFIG.domainsDBURL;
if (updateIntervalElement) updateIntervalElement.value = data.updateInterval || DEFAULT_CONFIG.updateInterval;
if (warningTemplateElement) {
warningTemplateElement.value = data.warningTemplate || defaultValues.warningTemplate;
warningTemplateElement.value = data.warningTemplate || DEFAULT_CONFIG.warningTemplate;
}
});
// Save settings when clicking "Save"
if (saveButton) {
saveButton.addEventListener("click", function () {
const apiKey = apiKeyElement && apiKeyElement.value.trim() ? apiKeyElement.value.trim() : defaultValues.safeBrowsingApiKey;
const domainsDBURL = domainsDBURLElement && domainsDBURLElement.value.trim() ? domainsDBURLElement.value.trim() : defaultValues.domainsDBURL;
const apiKey = apiKeyElement && apiKeyElement.value.trim() ? apiKeyElement.value.trim() : DEFAULT_CONFIG.apiKey;
const domainsDBURL = domainsDBURLElement && domainsDBURLElement.value.trim() ? domainsDBURLElement.value.trim() : DEFAULT_CONFIG.domainsDBURL;
const updateInterval = updateIntervalElement && updateIntervalElement.value.trim()
? parseInt(updateIntervalElement.value.trim()) || defaultValues.updateInterval
: defaultValues.updateInterval;
? parseInt(updateIntervalElement.value.trim()) || DEFAULT_CONFIG.updateInterval
: DEFAULT_CONFIG.updateInterval;
const warningTemplate = warningTemplateElement && warningTemplateElement.value.trim()
? warningTemplateElement.value.trim()
: defaultValues.warningTemplate;
: DEFAULT_CONFIG.warningTemplate;
chrome.storage.local.set({
safeBrowsingApiKey: apiKey,