- 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.
54 lines
2.8 KiB
JavaScript
54 lines
2.8 KiB
JavaScript
document.addEventListener("DOMContentLoaded", function () {
|
|
// Get UI elements safely
|
|
const apiKeyElement = document.getElementById("apiKey");
|
|
const domainsDBURLElement = document.getElementById("domainsDBURL");
|
|
const updateIntervalElement = document.getElementById("updateInterval");
|
|
const warningTemplateElement = document.getElementById("warningTemplate");
|
|
const saveButton = document.getElementById("save");
|
|
|
|
// Check if warningTemplateElement exists before setting value
|
|
if (!warningTemplateElement) {
|
|
console.error("⚠️ Element with ID 'warningTemplate' not found in options.html!");
|
|
}
|
|
|
|
// 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.'
|
|
};
|
|
|
|
// Load stored settings and apply defaults where needed
|
|
chrome.storage.local.get(["safeBrowsingApiKey", "domainsDBURL", "updateInterval", "warningTemplate"], function (data) {
|
|
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 || DEFAULT_CONFIG.warningTemplate;
|
|
}
|
|
});
|
|
|
|
// Save settings when clicking "Save"
|
|
if (saveButton) {
|
|
saveButton.addEventListener("click", function () {
|
|
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()) || DEFAULT_CONFIG.updateInterval
|
|
: DEFAULT_CONFIG.updateInterval;
|
|
const warningTemplate = warningTemplateElement && warningTemplateElement.value.trim()
|
|
? warningTemplateElement.value.trim()
|
|
: DEFAULT_CONFIG.warningTemplate;
|
|
|
|
chrome.storage.local.set({
|
|
safeBrowsingApiKey: apiKey,
|
|
domainsDBURL: domainsDBURL,
|
|
updateInterval: updateInterval,
|
|
warningTemplate: warningTemplate
|
|
}, function () {
|
|
alert("✅ Settings saved successfully!");
|
|
});
|
|
});
|
|
}
|
|
}); |