rapid interations of server side app and firefox extension

This commit is contained in:
Bryan Van Deusen
2026-01-24 22:52:51 -05:00
commit b9b8048a2d
81 changed files with 9675 additions and 0 deletions
+287
View File
@@ -0,0 +1,287 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>GallerySubscriber Settings</title>
<style>
:root {
--primary-color: #1976d2;
--success-color: #4caf50;
--error-color: #f44336;
--bg-color: #f5f5f5;
--card-bg: #ffffff;
--text-color: #212121;
--text-secondary: #757575;
--border-color: #e0e0e0;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 14px;
color: var(--text-color);
background: var(--bg-color);
padding: 24px;
min-height: 100vh;
}
.container {
max-width: 600px;
margin: 0 auto;
}
h1 {
font-size: 24px;
font-weight: 500;
margin-bottom: 24px;
color: var(--text-color);
}
.card {
background: var(--card-bg);
border-radius: 8px;
padding: 20px;
margin-bottom: 16px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card h2 {
font-size: 16px;
font-weight: 600;
margin-bottom: 16px;
color: var(--text-color);
}
.form-group {
margin-bottom: 16px;
}
.form-group:last-child {
margin-bottom: 0;
}
label {
display: block;
font-weight: 500;
margin-bottom: 6px;
color: var(--text-color);
}
input[type="text"],
input[type="url"],
input[type="password"] {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--border-color);
border-radius: 6px;
font-size: 14px;
transition: border-color 0.15s;
}
input:focus {
outline: none;
border-color: var(--primary-color);
}
.help-text {
font-size: 12px;
color: var(--text-secondary);
margin-top: 4px;
}
.input-with-button {
display: flex;
gap: 8px;
}
.input-with-button input {
flex: 1;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10px 20px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background 0.15s ease;
}
.btn-primary {
background: var(--primary-color);
color: white;
}
.btn-primary:hover {
background: #1565c0;
}
.btn-secondary {
background: #f5f5f5;
color: var(--text-color);
border: 1px solid var(--border-color);
}
.btn-secondary:hover {
background: #eeeeee;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn-small {
padding: 8px 12px;
font-size: 13px;
}
.actions {
display: flex;
gap: 12px;
align-items: center;
margin-top: 20px;
}
.result {
font-size: 13px;
padding: 4px 8px;
border-radius: 4px;
}
.result.success {
background: #e8f5e9;
color: #2e7d32;
}
.result.error {
background: #ffebee;
color: #c62828;
}
.connection-test {
display: flex;
align-items: center;
gap: 12px;
margin-top: 12px;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #9e9e9e;
}
.status-dot.connected {
background: var(--success-color);
}
.status-dot.error {
background: var(--error-color);
}
.instructions {
background: #e3f2fd;
border-radius: 6px;
padding: 16px;
margin-bottom: 16px;
}
.instructions h3 {
font-size: 14px;
font-weight: 600;
margin-bottom: 8px;
color: #1565c0;
}
.instructions ol {
margin-left: 20px;
font-size: 13px;
color: var(--text-color);
}
.instructions li {
margin-bottom: 4px;
}
.instructions code {
background: rgba(0,0,0,0.08);
padding: 2px 6px;
border-radius: 3px;
font-family: monospace;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>GallerySubscriber Extension Settings</h1>
<div class="instructions">
<h3>Setup Instructions</h3>
<ol>
<li>Open your GallerySubscriber web interface</li>
<li>Go to <strong>Settings</strong> page</li>
<li>Copy the <strong>Extension API Key</strong></li>
<li>Paste the API URL and key below</li>
</ol>
</div>
<div class="card">
<h2>Backend Connection</h2>
<div class="form-group">
<label for="api-url">API URL</label>
<input
type="url"
id="api-url"
placeholder="http://localhost:8080/api"
>
<p class="help-text">
The URL of your GallerySubscriber backend. Include <code>/api</code> at the end.
</p>
</div>
<div class="form-group">
<label for="api-key">Extension API Key</label>
<div class="input-with-button">
<input
type="password"
id="api-key"
placeholder="Your API key from Settings page"
>
<button type="button" id="toggle-key-btn" class="btn btn-secondary btn-small">
Show
</button>
</div>
<p class="help-text">
Find this in GallerySubscriber: Settings > Extension API Key
</p>
</div>
<div class="connection-test">
<button id="test-btn" class="btn btn-secondary btn-small">Test Connection</button>
<span id="test-status" class="status-dot"></span>
<span id="test-message"></span>
</div>
</div>
<div class="actions">
<button id="save-btn" class="btn btn-primary">Save Settings</button>
<span id="save-result" class="result"></span>
</div>
</div>
<script src="options.js"></script>
</body>
</html>
+183
View File
@@ -0,0 +1,183 @@
/**
* Options page script
*/
document.addEventListener('DOMContentLoaded', async () => {
await loadSettings();
setupEventListeners();
});
/**
* Load saved settings into form
*/
async function loadSettings() {
const config = await browser.storage.local.get(['apiUrl', 'apiKey']);
document.getElementById('api-url').value = config.apiUrl || '';
document.getElementById('api-key').value = config.apiKey || '';
}
/**
* Setup event listeners
*/
function setupEventListeners() {
// Toggle API key visibility
const toggleBtn = document.getElementById('toggle-key-btn');
const apiKeyInput = document.getElementById('api-key');
toggleBtn.addEventListener('click', () => {
if (apiKeyInput.type === 'password') {
apiKeyInput.type = 'text';
toggleBtn.textContent = 'Hide';
} else {
apiKeyInput.type = 'password';
toggleBtn.textContent = 'Show';
}
});
// Test connection
document.getElementById('test-btn').addEventListener('click', testConnection);
// Save settings
document.getElementById('save-btn').addEventListener('click', saveSettings);
// Auto-save on enter key
document.getElementById('api-url').addEventListener('keypress', (e) => {
if (e.key === 'Enter') saveSettings();
});
document.getElementById('api-key').addEventListener('keypress', (e) => {
if (e.key === 'Enter') saveSettings();
});
}
/**
* Test connection to backend
*/
async function testConnection() {
const testBtn = document.getElementById('test-btn');
const statusDot = document.getElementById('test-status');
const testMessage = document.getElementById('test-message');
testBtn.disabled = true;
testBtn.textContent = 'Testing...';
statusDot.className = 'status-dot';
testMessage.textContent = '';
// Get current values
const apiUrl = normalizeApiUrl(document.getElementById('api-url').value.trim());
const apiKey = document.getElementById('api-key').value.trim();
if (!apiUrl || !apiKey) {
statusDot.className = 'status-dot error';
testMessage.textContent = 'Please fill in both fields';
testBtn.disabled = false;
testBtn.textContent = 'Test Connection';
return;
}
// Temporarily save for testing
await browser.storage.local.set({ apiUrl, apiKey });
try {
const result = await browser.runtime.sendMessage({ type: 'TEST_CONNECTION' });
if (result.connected) {
statusDot.className = 'status-dot connected';
testMessage.textContent = 'Connected successfully!';
} else {
statusDot.className = 'status-dot error';
testMessage.textContent = result.error || 'Connection failed';
}
} catch (error) {
statusDot.className = 'status-dot error';
testMessage.textContent = error.message;
} finally {
testBtn.disabled = false;
testBtn.textContent = 'Test Connection';
}
}
/**
* Save settings
*/
async function saveSettings() {
const saveBtn = document.getElementById('save-btn');
const saveResult = document.getElementById('save-result');
saveBtn.disabled = true;
saveResult.textContent = '';
saveResult.className = 'result';
let apiUrl = document.getElementById('api-url').value.trim();
const apiKey = document.getElementById('api-key').value.trim();
// Validate
if (!apiUrl) {
showSaveResult('API URL is required', 'error');
saveBtn.disabled = false;
return;
}
if (!apiKey) {
showSaveResult('API Key is required', 'error');
saveBtn.disabled = false;
return;
}
// Normalize URL
apiUrl = normalizeApiUrl(apiUrl);
document.getElementById('api-url').value = apiUrl;
// Save
try {
await browser.storage.local.set({ apiUrl, apiKey });
await browser.runtime.sendMessage({
type: 'SAVE_CONFIG',
config: { apiUrl, apiKey }
});
showSaveResult('Settings saved!', 'success');
} catch (error) {
showSaveResult(`Failed to save: ${error.message}`, 'error');
} finally {
saveBtn.disabled = false;
}
}
/**
* Normalize API URL to ensure it ends with /api
* @param {string} url - Input URL
* @returns {string} - Normalized URL
*/
function normalizeApiUrl(url) {
if (!url) return '';
// Remove trailing slash
url = url.replace(/\/+$/, '');
// Ensure it ends with /api
if (!url.endsWith('/api')) {
url = url + '/api';
}
return url;
}
/**
* Show save result message
* @param {string} message - Message to display
* @param {string} type - 'success' or 'error'
*/
function showSaveResult(message, type) {
const saveResult = document.getElementById('save-result');
saveResult.textContent = message;
saveResult.className = `result ${type}`;
// Auto-hide success messages
if (type === 'success') {
setTimeout(() => {
saveResult.textContent = '';
saveResult.className = 'result';
}, 3000);
}
}