first commit
This commit is contained in:
42
options/options.js
Normal file
42
options/options.js
Normal file
@@ -0,0 +1,42 @@
|
||||
// Load saved settings on page load
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const result = await browser.storage.local.get('serverUrl');
|
||||
if (result.serverUrl) {
|
||||
document.getElementById('serverUrl').value = result.serverUrl;
|
||||
}
|
||||
});
|
||||
|
||||
// Save settings
|
||||
document.getElementById('save').addEventListener('click', async () => {
|
||||
const serverUrl = document.getElementById('serverUrl').value.trim();
|
||||
const statusEl = document.getElementById('status');
|
||||
|
||||
// Validate URL
|
||||
if (!serverUrl) {
|
||||
statusEl.textContent = 'Please enter a server URL';
|
||||
statusEl.className = 'status error';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(serverUrl);
|
||||
} catch {
|
||||
statusEl.textContent = 'Please enter a valid URL';
|
||||
statusEl.className = 'status error';
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove trailing slash for consistency
|
||||
const normalizedUrl = serverUrl.replace(/\/+$/, '');
|
||||
|
||||
// Save to storage
|
||||
await browser.storage.local.set({ serverUrl: normalizedUrl });
|
||||
|
||||
statusEl.textContent = 'Settings saved!';
|
||||
statusEl.className = 'status success';
|
||||
|
||||
// Hide status after 2 seconds
|
||||
setTimeout(() => {
|
||||
statusEl.className = 'status';
|
||||
}, 2000);
|
||||
});
|
||||
Reference in New Issue
Block a user