feat: ШАГ 3 — Chrome-расширение Verstak Bridge
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
/* Verstak Bridge Popup */
|
||||
|
||||
:root {
|
||||
--bg: #1a1a2e;
|
||||
--surface: #16213e;
|
||||
--surface2: #1e2d50;
|
||||
--accent: #0f9b8e;
|
||||
--accent-glow: rgba(15, 155, 142, 0.3);
|
||||
--text: #e0e0e0;
|
||||
--text-dim: #8892b0;
|
||||
--danger: #e74c3c;
|
||||
--success: #2ecc71;
|
||||
--radius: 8px;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 320px;
|
||||
min-height: 400px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dot.online {
|
||||
background: var(--success);
|
||||
box-shadow: 0 0 6px var(--success);
|
||||
}
|
||||
|
||||
.dot.offline {
|
||||
background: var(--danger);
|
||||
box-shadow: 0 0 6px var(--danger);
|
||||
}
|
||||
|
||||
.info {
|
||||
background: var(--surface);
|
||||
border-radius: var(--radius);
|
||||
padding: 8px 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.value {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.value.offline {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.value.online {
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
/* Toggle switch */
|
||||
.controls {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.toggle input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.slider {
|
||||
width: 36px;
|
||||
height: 20px;
|
||||
background: var(--surface2);
|
||||
border-radius: 10px;
|
||||
position: relative;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.slider::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
background: var(--text-dim);
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.toggle input:checked + .slider {
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.toggle input:checked + .slider::after {
|
||||
left: 18px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.toggle-label {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
/* Recent events */
|
||||
.recent {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.recent h2 {
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-dim);
|
||||
margin-bottom: 6px;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
#event-list {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.event-item {
|
||||
background: var(--surface);
|
||||
border-radius: 6px;
|
||||
padding: 6px 8px;
|
||||
margin-bottom: 4px;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.event-item .domain {
|
||||
color: var(--accent);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.event-item .title {
|
||||
color: var(--text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.event-item .duration {
|
||||
color: var(--text-dim);
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.empty {
|
||||
color: var(--text-dim);
|
||||
font-style: italic;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* Footer buttons */
|
||||
footer {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
padding: 8px;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
transition: background 0.2s;
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #0d8a7e;
|
||||
}
|
||||
|
||||
.btn.secondary {
|
||||
background: var(--surface2);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.btn.secondary:hover {
|
||||
background: #253a60;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Verstak Bridge</title>
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>Verstak Bridge</h1>
|
||||
<span id="status-dot" class="dot offline"></span>
|
||||
</header>
|
||||
|
||||
<section class="info">
|
||||
<div class="row">
|
||||
<span class="label">Сервер</span>
|
||||
<span id="bridge-status" class="value offline">Недоступен</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span class="label">Очередь</span>
|
||||
<span id="queue-count" class="value">—</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span class="label">Порт</span>
|
||||
<span id="bridge-port" class="value">—</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="controls">
|
||||
<label class="toggle">
|
||||
<input type="checkbox" id="track-toggle" checked>
|
||||
<span class="slider"></span>
|
||||
<span class="toggle-label">Отслеживать вкладки</span>
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<section class="recent">
|
||||
<h2>Последние события</h2>
|
||||
<div id="event-list">
|
||||
<p class="empty">Нет событий</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<button id="sync-btn" class="btn">🔄 Отправить сейчас</button>
|
||||
<button id="config-btn" class="btn secondary">⚙ Настройки</button>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,127 @@
|
||||
// Verstak Bridge — Popup Script
|
||||
// Shows connection status, queue count, and recent events.
|
||||
|
||||
const STORAGE_KEY = 'verstak_queue';
|
||||
const BRIDGE_KEY = 'verstak_bridge_config';
|
||||
const RECENT_KEY = 'verstak_recent';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateUI();
|
||||
restoreToggleState();
|
||||
|
||||
document.getElementById('sync-btn').addEventListener('click', forceSync);
|
||||
document.getElementById('track-toggle').addEventListener('change', onToggle);
|
||||
document.getElementById('config-btn').addEventListener('click', () => {
|
||||
// For now, just show bridge config in console
|
||||
chrome.storage.local.get(BRIDGE_KEY, (data) => {
|
||||
console.log('[verstak] bridge config:', data[BRIDGE_KEY]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function updateUI() {
|
||||
chrome.storage.local.get([STORAGE_KEY, BRIDGE_KEY, RECENT_KEY], (data) => {
|
||||
const queue = data[STORAGE_KEY] || [];
|
||||
const config = data[BRIDGE_KEY] || {};
|
||||
const recent = data[RECENT_KEY] || [];
|
||||
|
||||
// Queue count
|
||||
document.getElementById('queue-count').textContent = queue.length;
|
||||
|
||||
// Bridge status
|
||||
const statusEl = document.getElementById('bridge-status');
|
||||
const portEl = document.getElementById('bridge-port');
|
||||
const dotEl = document.getElementById('status-dot');
|
||||
|
||||
if (config.bridgeReachable) {
|
||||
statusEl.textContent = 'Доступен';
|
||||
statusEl.className = 'value online';
|
||||
dotEl.className = 'dot online';
|
||||
portEl.textContent = config.port || '?';
|
||||
} else {
|
||||
statusEl.textContent = 'Недоступен';
|
||||
statusEl.className = 'value offline';
|
||||
dotEl.className = 'dot offline';
|
||||
portEl.textContent = config.lastPing ? '—' : 'проверка...';
|
||||
}
|
||||
|
||||
// Recent events
|
||||
renderRecent(recent, config.bridgeReachable);
|
||||
});
|
||||
}
|
||||
|
||||
function renderRecent(events, reachable) {
|
||||
const list = document.getElementById('event-list');
|
||||
list.innerHTML = '';
|
||||
|
||||
if (!events || events.length === 0) {
|
||||
list.innerHTML = '<p class="empty">Нет событий</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Show last 5
|
||||
const lastFive = events.slice(-5).reverse();
|
||||
for (const ev of lastFive) {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'event-item';
|
||||
item.innerHTML = `
|
||||
<div class="domain">${escapeHtml(ev.domain || '?')}</div>
|
||||
<div class="title">${escapeHtml(truncate(ev.title || ev.url, 60))}</div>
|
||||
<div class="duration">${ev.active_seconds || 0}с${reachable ? '' : ' (ожидает)'}</div>
|
||||
`;
|
||||
list.appendChild(item);
|
||||
}
|
||||
}
|
||||
|
||||
function forceSync() {
|
||||
const btn = document.getElementById('sync-btn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = '⏳ Отправка...';
|
||||
|
||||
// Ask background to flush
|
||||
chrome.runtime.sendMessage({ type: 'FORCE_FLUSH' }, (response) => {
|
||||
setTimeout(() => {
|
||||
updateUI();
|
||||
btn.disabled = false;
|
||||
btn.textContent = '🔄 Отправить сейчас';
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
function onToggle(e) {
|
||||
const enabled = e.target.checked;
|
||||
chrome.storage.local.set({ 'verstak_tracking_enabled': enabled });
|
||||
|
||||
// Notify background
|
||||
chrome.runtime.sendMessage({ type: 'SET_TRACKING', enabled });
|
||||
}
|
||||
|
||||
function restoreToggleState() {
|
||||
chrome.storage.local.get('verstak_tracking_enabled', (data) => {
|
||||
const enabled = data.verstak_tracking_enabled !== false;
|
||||
document.getElementById('track-toggle').checked = enabled;
|
||||
});
|
||||
}
|
||||
|
||||
// Listen for updates from background
|
||||
chrome.runtime.onMessage.addListener((msg) => {
|
||||
if (msg.type === 'UI_UPDATE') {
|
||||
updateUI();
|
||||
}
|
||||
});
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
function truncate(s, n) {
|
||||
if (!s) return '';
|
||||
return s.length > n ? s.substring(0, n) + '...' : s;
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
if (!s) return '';
|
||||
return s
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
Reference in New Issue
Block a user