rapid interations of server side app and firefox extension
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
:root {
|
||||
--primary-color: #1976d2;
|
||||
--success-color: #4caf50;
|
||||
--warning-color: #ff9800;
|
||||
--error-color: #f44336;
|
||||
--bg-color: #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);
|
||||
min-width: 320px;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.popup-container {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--error-color);
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.status-indicator.connected {
|
||||
background: var(--success-color);
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.section h2 {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 8px;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.platforms-grid {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.platform-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
background: var(--bg-color);
|
||||
}
|
||||
|
||||
.platform-card:hover:not(.disabled) {
|
||||
border-color: var(--primary-color);
|
||||
background: #f5f9ff;
|
||||
}
|
||||
|
||||
.platform-card.disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.platform-card .platform-icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 10px;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.platform-card .info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.platform-card .name {
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.platform-card .status {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.platform-card .status.ready {
|
||||
color: var(--success-color);
|
||||
}
|
||||
|
||||
.platform-card .status.no-cookies {
|
||||
color: var(--warning-color);
|
||||
}
|
||||
|
||||
.platform-card .status.error {
|
||||
color: var(--error-color);
|
||||
}
|
||||
|
||||
.platform-card .action-icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
opacity: 0.5;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.platform-card.loading .action-icon {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 10px 16px;
|
||||
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-icon {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 6px;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
color: var(--text-secondary);
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-icon:hover {
|
||||
background: #f5f5f5;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mt-2 {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.alert strong {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.alert p {
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.alert-warning {
|
||||
background: #fff8e1;
|
||||
border: 1px solid #ffcc02;
|
||||
color: #795548;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
padding: 10px 12px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.status-message.success {
|
||||
background: #e8f5e9;
|
||||
color: #2e7d32;
|
||||
border: 1px solid #a5d6a7;
|
||||
}
|
||||
|
||||
.status-message.error {
|
||||
background: #ffebee;
|
||||
color: #c62828;
|
||||
border: 1px solid #ef9a9a;
|
||||
}
|
||||
|
||||
.status-message.warning {
|
||||
background: #fff8e1;
|
||||
color: #795548;
|
||||
border: 1px solid #ffcc02;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.version {
|
||||
font-size: 11px;
|
||||
color: #9e9e9e;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="popup-container">
|
||||
<header class="header">
|
||||
<img src="../icons/icon-32.png" alt="GallerySubscriber" class="logo">
|
||||
<h1>GallerySubscriber</h1>
|
||||
<span id="connection-status" class="status-indicator" title="Disconnected"></span>
|
||||
</header>
|
||||
|
||||
<!-- Not Configured State -->
|
||||
<div id="setup-required" class="section hidden">
|
||||
<div class="alert alert-warning">
|
||||
<strong>Setup Required</strong>
|
||||
<p>Please configure your API URL and key in settings.</p>
|
||||
</div>
|
||||
<button id="open-settings-btn" class="btn btn-primary full-width">
|
||||
Open Settings
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div id="main-content" class="hidden">
|
||||
<!-- Cookie Export Section -->
|
||||
<section class="section">
|
||||
<h2>Export Cookies</h2>
|
||||
<div id="platforms-list" class="platforms-grid">
|
||||
<!-- Populated by JavaScript -->
|
||||
</div>
|
||||
<button id="export-all-btn" class="btn btn-secondary full-width mt-2">
|
||||
Export All Platforms
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<!-- Status Messages -->
|
||||
<div id="status-message" class="status-message hidden"></div>
|
||||
</div>
|
||||
|
||||
<footer class="footer">
|
||||
<button id="settings-btn" class="btn-icon" title="Settings">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<span class="version">v1.0.0</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="../lib/platforms.js"></script>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,272 @@
|
||||
/**
|
||||
* Popup script - handles UI interactions
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
await init();
|
||||
});
|
||||
|
||||
/**
|
||||
* Initialize the popup
|
||||
*/
|
||||
async function init() {
|
||||
// Check configuration
|
||||
const config = await browser.runtime.sendMessage({ type: 'GET_CONFIG' });
|
||||
|
||||
if (!config.apiUrl || !config.apiKey) {
|
||||
showSetupRequired();
|
||||
return;
|
||||
}
|
||||
|
||||
// Test connection
|
||||
const connectionStatus = await browser.runtime.sendMessage({ type: 'TEST_CONNECTION' });
|
||||
updateConnectionIndicator(connectionStatus.connected);
|
||||
|
||||
// Show main content
|
||||
document.getElementById('setup-required').classList.add('hidden');
|
||||
document.getElementById('main-content').classList.remove('hidden');
|
||||
|
||||
if (!connectionStatus.connected) {
|
||||
showError(`Cannot connect to backend: ${connectionStatus.error}`);
|
||||
}
|
||||
|
||||
// Load platform status
|
||||
await loadPlatformStatus();
|
||||
|
||||
// Setup event listeners
|
||||
setupEventListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the setup required message
|
||||
*/
|
||||
function showSetupRequired() {
|
||||
document.getElementById('setup-required').classList.remove('hidden');
|
||||
document.getElementById('main-content').classList.add('hidden');
|
||||
|
||||
document.getElementById('open-settings-btn').addEventListener('click', () => {
|
||||
browser.runtime.openOptionsPage();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the connection status indicator
|
||||
* @param {boolean} connected - Whether connected to backend
|
||||
*/
|
||||
function updateConnectionIndicator(connected) {
|
||||
const indicator = document.getElementById('connection-status');
|
||||
indicator.classList.toggle('connected', connected);
|
||||
indicator.title = connected ? 'Connected to GallerySubscriber' : 'Disconnected';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and display platform status
|
||||
*/
|
||||
async function loadPlatformStatus() {
|
||||
const status = await browser.runtime.sendMessage({ type: 'GET_PLATFORM_STATUS' });
|
||||
const container = document.getElementById('platforms-list');
|
||||
container.innerHTML = '';
|
||||
|
||||
for (const [key, platform] of Object.entries(PLATFORMS)) {
|
||||
const platformStatus = status[key] || {};
|
||||
const card = createPlatformCard(key, platform, platformStatus);
|
||||
container.appendChild(card);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a platform card element
|
||||
* @param {string} key - Platform key
|
||||
* @param {object} platform - Platform definition
|
||||
* @param {object} status - Platform status
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
function createPlatformCard(key, platform, status) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'platform-card';
|
||||
card.dataset.platform = key;
|
||||
|
||||
const isDisabled = platform.authType === 'token';
|
||||
if (isDisabled) {
|
||||
card.classList.add('disabled');
|
||||
}
|
||||
|
||||
const statusText = getStatusText(status, platform);
|
||||
const statusClass = getStatusClass(status, platform);
|
||||
|
||||
card.innerHTML = `
|
||||
<div class="platform-icon" style="background-color: ${platform.color}">
|
||||
${platform.name.charAt(0)}
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="name">${platform.name}</div>
|
||||
<div class="status ${statusClass}">${statusText}</div>
|
||||
</div>
|
||||
<span class="action-icon">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
||||
</svg>
|
||||
</span>
|
||||
`;
|
||||
|
||||
if (!isDisabled) {
|
||||
card.addEventListener('click', () => exportPlatformCookies(key, card));
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status text for display
|
||||
* @param {object} status - Platform status
|
||||
* @param {object} platform - Platform definition
|
||||
* @returns {string}
|
||||
*/
|
||||
function getStatusText(status, platform) {
|
||||
if (platform.authType === 'token') {
|
||||
return 'Manual token entry required';
|
||||
}
|
||||
if (status.error) {
|
||||
return 'Error checking cookies';
|
||||
}
|
||||
if (!status.hasCookies || status.cookieCount === 0) {
|
||||
return 'No cookies found - log in first';
|
||||
}
|
||||
return `${status.cookieCount} cookies ready`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status CSS class
|
||||
* @param {object} status - Platform status
|
||||
* @param {object} platform - Platform definition
|
||||
* @returns {string}
|
||||
*/
|
||||
function getStatusClass(status, platform) {
|
||||
if (platform.authType === 'token') {
|
||||
return 'no-cookies';
|
||||
}
|
||||
if (status.error) {
|
||||
return 'error';
|
||||
}
|
||||
if (!status.hasCookies || status.cookieCount === 0) {
|
||||
return 'no-cookies';
|
||||
}
|
||||
return 'ready';
|
||||
}
|
||||
|
||||
/**
|
||||
* Export cookies for a single platform
|
||||
* @param {string} platformKey - Platform key
|
||||
* @param {HTMLElement} cardElement - The card element
|
||||
*/
|
||||
async function exportPlatformCookies(platformKey, cardElement) {
|
||||
cardElement.classList.add('loading');
|
||||
hideStatusMessage();
|
||||
|
||||
try {
|
||||
const result = await browser.runtime.sendMessage({
|
||||
type: 'EXPORT_COOKIES',
|
||||
platform: platformKey
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
showError(result.error);
|
||||
} else {
|
||||
showSuccess(`${PLATFORMS[platformKey].name}: ${result.cookieCount} cookies exported!`);
|
||||
// Refresh status
|
||||
await loadPlatformStatus();
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
} finally {
|
||||
cardElement.classList.remove('loading');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export cookies for all platforms
|
||||
*/
|
||||
async function exportAllCookies() {
|
||||
const btn = document.getElementById('export-all-btn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Exporting...';
|
||||
hideStatusMessage();
|
||||
|
||||
try {
|
||||
const results = await browser.runtime.sendMessage({ type: 'EXPORT_ALL_COOKIES' });
|
||||
|
||||
const successes = Object.values(results).filter(r => r.success).length;
|
||||
const skipped = Object.values(results).filter(r => r.skipped).length;
|
||||
const failures = Object.values(results).filter(r => !r.success && !r.skipped).length;
|
||||
|
||||
if (failures === 0 && successes > 0) {
|
||||
showSuccess(`Exported ${successes} platform(s) successfully!`);
|
||||
} else if (successes > 0) {
|
||||
showWarning(`${successes} succeeded, ${failures} failed`);
|
||||
} else if (failures > 0) {
|
||||
showError('All exports failed. Are you logged in?');
|
||||
} else {
|
||||
showWarning('No platforms to export');
|
||||
}
|
||||
|
||||
await loadPlatformStatus();
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Export All Platforms';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup event listeners
|
||||
*/
|
||||
function setupEventListeners() {
|
||||
document.getElementById('export-all-btn').addEventListener('click', exportAllCookies);
|
||||
document.getElementById('settings-btn').addEventListener('click', () => {
|
||||
browser.runtime.openOptionsPage();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show success message
|
||||
* @param {string} message - Message to display
|
||||
*/
|
||||
function showSuccess(message) {
|
||||
showStatusMessage(message, 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show error message
|
||||
* @param {string} message - Message to display
|
||||
*/
|
||||
function showError(message) {
|
||||
showStatusMessage(message, 'error');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show warning message
|
||||
* @param {string} message - Message to display
|
||||
*/
|
||||
function showWarning(message) {
|
||||
showStatusMessage(message, 'warning');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a status message
|
||||
* @param {string} message - Message text
|
||||
* @param {string} type - Message type (success, error, warning)
|
||||
*/
|
||||
function showStatusMessage(message, type) {
|
||||
const el = document.getElementById('status-message');
|
||||
el.textContent = message;
|
||||
el.className = `status-message ${type}`;
|
||||
el.classList.remove('hidden');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the status message
|
||||
*/
|
||||
function hideStatusMessage() {
|
||||
document.getElementById('status-message').classList.add('hidden');
|
||||
}
|
||||
Reference in New Issue
Block a user